mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-23 03:51:29 +00:00
943dec525c
* Delete deploy contract tool. Move mock to its own package as testonly with some helper functions * gofmt contracts/deposit/mock/mock.go * move stategen mock.go to its on testonly pkg * move password_reader_mock.go to mock testonly package * move mock keymanager to its own testonly package * move attestations mock * move voluntaryexits mock * Move slashings mock to mock pkg * move the slasher mock Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
95 lines
3.3 KiB
Go
95 lines
3.3 KiB
Go
package deposit_test
|
|
|
|
import (
|
|
"strconv"
|
|
"testing"
|
|
|
|
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
|
"github.com/prysmaticlabs/prysm/config/params"
|
|
"github.com/prysmaticlabs/prysm/container/trie"
|
|
depositcontract "github.com/prysmaticlabs/prysm/contracts/deposit/mock"
|
|
"github.com/prysmaticlabs/prysm/runtime/interop"
|
|
"github.com/prysmaticlabs/prysm/testing/assert"
|
|
"github.com/prysmaticlabs/prysm/testing/require"
|
|
)
|
|
|
|
func TestDepositTrieRoot_OK(t *testing.T) {
|
|
testAcc, err := depositcontract.Setup()
|
|
require.NoError(t, err)
|
|
|
|
localTrie, err := trie.NewTrie(params.BeaconConfig().DepositContractTreeDepth)
|
|
require.NoError(t, err)
|
|
|
|
depRoot, err := testAcc.Contract.GetDepositRoot(&bind.CallOpts{})
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, depRoot, localTrie.HashTreeRoot(), "Local deposit trie root and contract deposit trie root are not equal")
|
|
|
|
privKeys, pubKeys, err := interop.DeterministicallyGenerateKeys(0 /*startIndex*/, 101)
|
|
require.NoError(t, err)
|
|
depositDataItems, depositDataRoots, err := interop.DepositDataFromKeys(privKeys, pubKeys)
|
|
require.NoError(t, err)
|
|
|
|
testAcc.TxOpts.Value = depositcontract.Amount32Eth()
|
|
|
|
for i := 0; i < 100; i++ {
|
|
data := depositDataItems[i]
|
|
dataRoot := [32]byte{}
|
|
copy(dataRoot[:], depositDataRoots[i])
|
|
|
|
_, err := testAcc.Contract.Deposit(testAcc.TxOpts, data.PublicKey, data.WithdrawalCredentials, data.Signature, dataRoot)
|
|
require.NoError(t, err, "Could not deposit to deposit contract")
|
|
|
|
testAcc.Backend.Commit()
|
|
item, err := data.HashTreeRoot()
|
|
require.NoError(t, err)
|
|
|
|
assert.NoError(t, localTrie.Insert(item[:], i))
|
|
depRoot, err = testAcc.Contract.GetDepositRoot(&bind.CallOpts{})
|
|
require.NoError(t, err)
|
|
assert.Equal(t, depRoot, localTrie.HashTreeRoot(), "Local deposit trie root and contract deposit trie root are not equal for index %d", i)
|
|
}
|
|
}
|
|
|
|
func TestDepositTrieRoot_Fail(t *testing.T) {
|
|
testAcc, err := depositcontract.Setup()
|
|
require.NoError(t, err)
|
|
|
|
localTrie, err := trie.NewTrie(params.BeaconConfig().DepositContractTreeDepth)
|
|
require.NoError(t, err)
|
|
|
|
depRoot, err := testAcc.Contract.GetDepositRoot(&bind.CallOpts{})
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, depRoot, localTrie.HashTreeRoot(), "Local deposit trie root and contract deposit trie root are not equal")
|
|
|
|
privKeys, pubKeys, err := interop.DeterministicallyGenerateKeys(0 /*startIndex*/, 101)
|
|
require.NoError(t, err)
|
|
depositDataItems, depositDataRoots, err := interop.DepositDataFromKeys(privKeys, pubKeys)
|
|
require.NoError(t, err)
|
|
testAcc.TxOpts.Value = depositcontract.Amount32Eth()
|
|
|
|
for i := 0; i < 100; i++ {
|
|
data := depositDataItems[i]
|
|
dataRoot := [32]byte{}
|
|
copy(dataRoot[:], depositDataRoots[i])
|
|
|
|
_, err := testAcc.Contract.Deposit(testAcc.TxOpts, data.PublicKey, data.WithdrawalCredentials, data.Signature, dataRoot)
|
|
require.NoError(t, err, "Could not deposit to deposit contract")
|
|
|
|
// Change an element in the data when storing locally
|
|
copy(data.PublicKey, strconv.Itoa(i+10))
|
|
|
|
testAcc.Backend.Commit()
|
|
item, err := data.HashTreeRoot()
|
|
require.NoError(t, err)
|
|
|
|
assert.NoError(t, localTrie.Insert(item[:], i))
|
|
|
|
depRoot, err = testAcc.Contract.GetDepositRoot(&bind.CallOpts{})
|
|
require.NoError(t, err)
|
|
|
|
assert.NotEqual(t, depRoot, localTrie.HashTreeRoot(), "Local deposit trie root and contract deposit trie root are equal for index %d", i)
|
|
}
|
|
}
|