diff --git a/bindings/tests/auction/main_test.go b/bindings/tests/auction/main_test.go index f9ad4a27b..fb0e4b31c 100644 --- a/bindings/tests/auction/main_test.go +++ b/bindings/tests/auction/main_test.go @@ -11,12 +11,13 @@ import ( "github.com/rocket-pool/smartnode/bindings/rocketpool" "github.com/rocket-pool/smartnode/bindings/tests" + "github.com/rocket-pool/smartnode/bindings/tests/testutils" "github.com/rocket-pool/smartnode/bindings/tests/testutils/accounts" "github.com/rocket-pool/smartnode/bindings/tests/utils" ) var ( - client *ethclient.Client + client *testutils.EthClientWrapper rp *rocketpool.RocketPool ownerAccount *accounts.Account @@ -31,10 +32,11 @@ func TestMain(m *testing.M) { var err error // Initialize eth client - client, err = ethclient.Dial(tests.Eth1ProviderAddress) + rawClient, err := ethclient.Dial(tests.Eth1ProviderAddress) if err != nil { log.Fatal(err) } + client = testutils.NewEthClientWrapper(rawClient) // Initialize contract manager rp, err = rocketpool.NewRocketPool(client, common.HexToAddress(tests.RocketStorageAddress)) diff --git a/bindings/tests/dao/main_test.go b/bindings/tests/dao/main_test.go index 6f0813258..c1233affe 100644 --- a/bindings/tests/dao/main_test.go +++ b/bindings/tests/dao/main_test.go @@ -11,12 +11,13 @@ import ( "github.com/rocket-pool/smartnode/bindings/rocketpool" "github.com/rocket-pool/smartnode/bindings/tests" + "github.com/rocket-pool/smartnode/bindings/tests/testutils" "github.com/rocket-pool/smartnode/bindings/tests/testutils/accounts" "github.com/rocket-pool/smartnode/bindings/tests/utils" ) var ( - client *ethclient.Client + client *testutils.EthClientWrapper rp *rocketpool.RocketPool ownerAccount *accounts.Account @@ -30,10 +31,11 @@ func TestMain(m *testing.M) { var err error // Initialize eth client - client, err = ethclient.Dial(tests.Eth1ProviderAddress) + rawClient, err := ethclient.Dial(tests.Eth1ProviderAddress) if err != nil { log.Fatal(err) } + client = testutils.NewEthClientWrapper(rawClient) // Initialize contract manager rp, err = rocketpool.NewRocketPool(client, common.HexToAddress(tests.RocketStorageAddress)) diff --git a/bindings/tests/dao/trustednode/main_test.go b/bindings/tests/dao/trustednode/main_test.go index 75aa2bd2e..105eacdc3 100644 --- a/bindings/tests/dao/trustednode/main_test.go +++ b/bindings/tests/dao/trustednode/main_test.go @@ -11,11 +11,12 @@ import ( "github.com/rocket-pool/smartnode/bindings/rocketpool" "github.com/rocket-pool/smartnode/bindings/tests" + "github.com/rocket-pool/smartnode/bindings/tests/testutils" "github.com/rocket-pool/smartnode/bindings/tests/testutils/accounts" ) var ( - client *ethclient.Client + client *testutils.EthClientWrapper rp *rocketpool.RocketPool ownerAccount *accounts.Account @@ -30,10 +31,11 @@ func TestMain(m *testing.M) { var err error // Initialize eth client - client, err = ethclient.Dial(tests.Eth1ProviderAddress) + rawClient, err := ethclient.Dial(tests.Eth1ProviderAddress) if err != nil { log.Fatal(err) } + client = testutils.NewEthClientWrapper(rawClient) // Initialize contract manager rp, err = rocketpool.NewRocketPool(client, common.HexToAddress(tests.RocketStorageAddress)) diff --git a/bindings/tests/deposit/main_test.go b/bindings/tests/deposit/main_test.go index b91d2707c..6654db421 100644 --- a/bindings/tests/deposit/main_test.go +++ b/bindings/tests/deposit/main_test.go @@ -11,11 +11,12 @@ import ( "github.com/rocket-pool/smartnode/bindings/rocketpool" "github.com/rocket-pool/smartnode/bindings/tests" + "github.com/rocket-pool/smartnode/bindings/tests/testutils" "github.com/rocket-pool/smartnode/bindings/tests/testutils/accounts" ) var ( - client *ethclient.Client + client *testutils.EthClientWrapper rp *rocketpool.RocketPool ownerAccount *accounts.Account @@ -27,10 +28,11 @@ func TestMain(m *testing.M) { var err error // Initialize eth client - client, err = ethclient.Dial(tests.Eth1ProviderAddress) + rawClient, err := ethclient.Dial(tests.Eth1ProviderAddress) if err != nil { log.Fatal(err) } + client = testutils.NewEthClientWrapper(rawClient) // Initialize contract manager rp, err = rocketpool.NewRocketPool(client, common.HexToAddress(tests.RocketStorageAddress)) diff --git a/bindings/tests/minipool/contract_test.go b/bindings/tests/minipool/contract_test.go index 99ab8b342..3f9a406ac 100644 --- a/bindings/tests/minipool/contract_test.go +++ b/bindings/tests/minipool/contract_test.go @@ -81,7 +81,7 @@ func TestDetails(t *testing.T) { } // Set minipool withdrawable status - if _, err := minipool.SubmitMinipoolWithdrawable(rp, mp.Address, trustedNodeAccount.GetTransactor()); err != nil { + if _, err := minipool.SubmitMinipoolWithdrawable(rp, mp.GetAddress(), trustedNodeAccount.GetTransactor()); err != nil { t.Fatal(err) } @@ -136,12 +136,12 @@ func TestDetails(t *testing.T) { t.Errorf("Incorrect minipool user deposit assigned time %v", user.DepositAssignedTime) } } - if withdrawalCredentials, err := minipool.GetMinipoolWithdrawalCredentials(rp, mp.Address, nil); err != nil { + if withdrawalCredentials, err := minipool.GetMinipoolWithdrawalCredentials(rp, mp.GetAddress(), nil); err != nil { t.Error(err) } else { withdrawalPrefix := byte(1) padding := make([]byte, 11) - expectedWithdrawalCredentials := bytes.Join([][]byte{{withdrawalPrefix}, padding, mp.Address.Bytes()}, []byte{}) + expectedWithdrawalCredentials := bytes.Join([][]byte{{withdrawalPrefix}, padding, mp.GetAddress().Bytes()}, []byte{}) if !bytes.Equal(withdrawalCredentials.Bytes(), expectedWithdrawalCredentials) { t.Errorf("Incorrect minipool withdrawal credentials %s", hex.EncodeToString(withdrawalCredentials.Bytes())) } @@ -228,7 +228,7 @@ func TestStake(t *testing.T) { if err != nil { t.Fatal(err) } - withdrawalCredentials, err := minipool.GetMinipoolWithdrawalCredentials(rp, mp.Address, nil) + withdrawalCredentials, err := minipool.GetMinipoolWithdrawalCredentials(rp, mp.GetAddress(), nil) if err != nil { t.Fatal(err) } @@ -345,7 +345,7 @@ func TestClose(t *testing.T) { } // Get & check initial minipool exists status - if exists, err := minipool.GetMinipoolExists(rp, mp.Address, nil); err != nil { + if exists, err := minipool.GetMinipoolExists(rp, mp.GetAddress(), nil); err != nil { t.Error(err) } else if !exists { t.Error("Incorrect initial minipool exists status") @@ -354,7 +354,7 @@ func TestClose(t *testing.T) { // Simulate a post-merge withdrawal by sending 16 ETH to the minipool opts := nodeAccount.GetTransactor() opts.Value = eth.EthToWei(16) - hash, err := eth.SendTransaction(rp.Client, mp.Address, big.NewInt(1337), opts) // Ganache's default chain ID is 1337 + hash, err := eth.SendTransaction(rp.Client, mp.GetAddress(), big.NewInt(1337), opts) // Ganache's default chain ID is 1337 if err != nil { t.Errorf("Error sending ETH to minipool: %s", err.Error()) } @@ -366,7 +366,7 @@ func TestClose(t *testing.T) { } // Get & check updated minipool exists status - if exists, err := minipool.GetMinipoolExists(rp, mp.Address, nil); err != nil { + if exists, err := minipool.GetMinipoolExists(rp, mp.GetAddress(), nil); err != nil { t.Error(err) } else if exists { t.Error("Incorrect updated minipool exists status") @@ -430,7 +430,7 @@ func TestWithdrawValidatorBalance(t *testing.T) { } // Set minipool withdrawable status - if _, err := minipool.SubmitMinipoolWithdrawable(rp, mp.Address, trustedNodeAccount.GetTransactor()); err != nil { + if _, err := minipool.SubmitMinipoolWithdrawable(rp, mp.GetAddress(), trustedNodeAccount.GetTransactor()); err != nil { t.Fatal(err) } @@ -443,7 +443,7 @@ func TestWithdrawValidatorBalance(t *testing.T) { // Withdraw minipool validator balance opts := swcAccount.GetTransactor() opts.Value = eth.EthToWei(32) - if _, err := mp.Contract.Transfer(opts); err != nil { + if _, err := mp.GetContract().Transfer(opts); err != nil { t.Fatal(err) } @@ -490,7 +490,7 @@ func TestWithdrawValidatorBalance(t *testing.T) { } // Confirm the minipool still exists - if exists, err := minipool.GetMinipoolExists(rp, mp.Address, nil); err != nil { + if exists, err := minipool.GetMinipoolExists(rp, mp.GetAddress(), nil); err != nil { t.Error(err) } else if !exists { t.Error("Minipool no longer exists but it should") @@ -548,7 +548,7 @@ func TestWithdrawValidatorBalanceAndFinalise(t *testing.T) { } // Set minipool withdrawable status - if _, err := minipool.SubmitMinipoolWithdrawable(rp, mp.Address, trustedNodeAccount.GetTransactor()); err != nil { + if _, err := minipool.SubmitMinipoolWithdrawable(rp, mp.GetAddress(), trustedNodeAccount.GetTransactor()); err != nil { t.Fatal(err) } @@ -561,7 +561,7 @@ func TestWithdrawValidatorBalanceAndFinalise(t *testing.T) { // Withdraw minipool validator balance opts := swcAccount.GetTransactor() opts.Value = eth.EthToWei(32) - if _, err := mp.Contract.Transfer(opts); err != nil { + if _, err := mp.GetContract().Transfer(opts); err != nil { t.Fatal(err) } @@ -603,7 +603,7 @@ func TestWithdrawValidatorBalanceAndFinalise(t *testing.T) { } // Confirm the minipool still exists - if exists, err := minipool.GetMinipoolExists(rp, mp.Address, nil); err != nil { + if exists, err := minipool.GetMinipoolExists(rp, mp.GetAddress(), nil); err != nil { t.Error(err) } else if !exists { t.Error("Minipool doesn't exist but it should") diff --git a/bindings/tests/minipool/main_test.go b/bindings/tests/minipool/main_test.go index 8f85c0155..418a56135 100644 --- a/bindings/tests/minipool/main_test.go +++ b/bindings/tests/minipool/main_test.go @@ -11,11 +11,12 @@ import ( "github.com/rocket-pool/smartnode/bindings/rocketpool" "github.com/rocket-pool/smartnode/bindings/tests" + "github.com/rocket-pool/smartnode/bindings/tests/testutils" "github.com/rocket-pool/smartnode/bindings/tests/testutils/accounts" ) var ( - client *ethclient.Client + client *testutils.EthClientWrapper rp *rocketpool.RocketPool ownerAccount *accounts.Account @@ -29,10 +30,11 @@ func TestMain(m *testing.M) { var err error // Initialize eth client - client, err = ethclient.Dial(tests.Eth1ProviderAddress) + rawClient, err := ethclient.Dial(tests.Eth1ProviderAddress) if err != nil { log.Fatal(err) } + client = testutils.NewEthClientWrapper(rawClient) // Initialize contract manager rp, err = rocketpool.NewRocketPool(client, common.HexToAddress(tests.RocketStorageAddress)) diff --git a/bindings/tests/minipool/minipool_test.go b/bindings/tests/minipool/minipool_test.go index 6a9131353..1abda819c 100644 --- a/bindings/tests/minipool/minipool_test.go +++ b/bindings/tests/minipool/minipool_test.go @@ -79,7 +79,7 @@ func TestMinipoolDetails(t *testing.T) { } // Mark minipool as withdrawable - if _, err := minipool.SubmitMinipoolWithdrawable(rp, mp.Address, trustedNodeAccount.GetTransactor()); err != nil { + if _, err := minipool.SubmitMinipoolWithdrawable(rp, mp.GetAddress(), trustedNodeAccount.GetTransactor()); err != nil { t.Fatal(err) } @@ -96,7 +96,7 @@ func TestMinipoolDetails(t *testing.T) { t.Error("Incorrect updated minipool count") } else { mpDetails := minipools[0] - if !bytes.Equal(mpDetails.Address.Bytes(), mp.Address.Bytes()) { + if !bytes.Equal(mpDetails.Address.Bytes(), mp.GetAddress().Bytes()) { t.Errorf("Incorrect minipool address %s", mpDetails.Address.Hex()) } if !mpDetails.Exists { @@ -118,7 +118,7 @@ func TestMinipoolDetails(t *testing.T) { t.Error(err) } else if len(nodeMinipools) != 1 { t.Error("Incorrect updated node minipool count") - } else if !bytes.Equal(nodeMinipools[0].Address.Bytes(), mp.Address.Bytes()) { + } else if !bytes.Equal(nodeMinipools[0].Address.Bytes(), mp.GetAddress().Bytes()) { t.Errorf("Incorrect node minipool address %s", nodeMinipools[0].Address.Hex()) } if nodeMinipoolPubkeys, err := minipool.GetNodeValidatingMinipoolPubkeys(rp, nodeAccount.Address, nil); err != nil { @@ -132,7 +132,7 @@ func TestMinipoolDetails(t *testing.T) { // Get & check minipool address by pubkey if minipoolAddress, err := minipool.GetMinipoolByPubkey(rp, validatorPubkey, nil); err != nil { t.Error(err) - } else if !bytes.Equal(minipoolAddress.Bytes(), mp.Address.Bytes()) { + } else if !bytes.Equal(minipoolAddress.Bytes(), mp.GetAddress().Bytes()) { t.Errorf("Incorrect minipool address %s for pubkey %s", minipoolAddress.Hex(), validatorPubkey.Hex()) } diff --git a/bindings/tests/minipool/status_test.go b/bindings/tests/minipool/status_test.go index 41bc685d6..057db5e4c 100644 --- a/bindings/tests/minipool/status_test.go +++ b/bindings/tests/minipool/status_test.go @@ -64,7 +64,7 @@ func TestSubmitMinipoolWithdrawable(t *testing.T) { } // Submit minipool withdrawable status - if _, err := minipool.SubmitMinipoolWithdrawable(rp, mp.Address, trustedNodeAccount.GetTransactor()); err != nil { + if _, err := minipool.SubmitMinipoolWithdrawable(rp, mp.GetAddress(), trustedNodeAccount.GetTransactor()); err != nil { t.Fatal(err) } diff --git a/bindings/tests/network/main_test.go b/bindings/tests/network/main_test.go index a32da6428..827ee1ca7 100644 --- a/bindings/tests/network/main_test.go +++ b/bindings/tests/network/main_test.go @@ -11,11 +11,12 @@ import ( "github.com/rocket-pool/smartnode/bindings/rocketpool" "github.com/rocket-pool/smartnode/bindings/tests" + "github.com/rocket-pool/smartnode/bindings/tests/testutils" "github.com/rocket-pool/smartnode/bindings/tests/testutils/accounts" ) var ( - client *ethclient.Client + client *testutils.EthClientWrapper rp *rocketpool.RocketPool ownerAccount *accounts.Account @@ -28,10 +29,11 @@ func TestMain(m *testing.M) { var err error // Initialize eth client - client, err = ethclient.Dial(tests.Eth1ProviderAddress) + rawClient, err := ethclient.Dial(tests.Eth1ProviderAddress) if err != nil { log.Fatal(err) } + client = testutils.NewEthClientWrapper(rawClient) // Initialize contract manager rp, err = rocketpool.NewRocketPool(client, common.HexToAddress(tests.RocketStorageAddress)) diff --git a/bindings/tests/node/main_test.go b/bindings/tests/node/main_test.go index e44d41caa..7fd191e04 100644 --- a/bindings/tests/node/main_test.go +++ b/bindings/tests/node/main_test.go @@ -10,11 +10,12 @@ import ( "github.com/rocket-pool/smartnode/bindings/rocketpool" "github.com/rocket-pool/smartnode/bindings/tests" + "github.com/rocket-pool/smartnode/bindings/tests/testutils" "github.com/rocket-pool/smartnode/bindings/tests/testutils/accounts" ) var ( - client *ethclient.Client + client *testutils.EthClientWrapper rp *rocketpool.RocketPool ownerAccount *accounts.Account @@ -26,10 +27,11 @@ func TestMain(m *testing.M) { var err error // Initialize eth client - client, err = ethclient.Dial(tests.Eth1ProviderAddress) + rawClient, err := ethclient.Dial(tests.Eth1ProviderAddress) if err != nil { log.Fatal(err) } + client = testutils.NewEthClientWrapper(rawClient) // Initialize contract manager rp, err = rocketpool.NewRocketPool(client, common.HexToAddress(tests.RocketStorageAddress)) diff --git a/bindings/tests/node/node_test.go b/bindings/tests/node/node_test.go index 20e4e6318..6fb677d97 100644 --- a/bindings/tests/node/node_test.go +++ b/bindings/tests/node/node_test.go @@ -32,7 +32,7 @@ func TestRegisterNode(t *testing.T) { } // Get & check initial node details - if details, err := node.GetNodes(rp, nil); err != nil { + if details, err := node.GetNodes(rp, false, nil); err != nil { t.Error(err) } else if len(details) != 0 { t.Error("Incorrect initial node count") @@ -45,7 +45,7 @@ func TestRegisterNode(t *testing.T) { } // Get & check updated node details - if details, err := node.GetNodes(rp, nil); err != nil { + if details, err := node.GetNodes(rp, false, nil); err != nil { t.Error(err) } else if len(details) != 1 { t.Error("Incorrect updated node count") diff --git a/bindings/tests/rewards/main_test.go b/bindings/tests/rewards/main_test.go index 999112a03..0c2f9621b 100644 --- a/bindings/tests/rewards/main_test.go +++ b/bindings/tests/rewards/main_test.go @@ -11,11 +11,12 @@ import ( "github.com/rocket-pool/smartnode/bindings/rocketpool" "github.com/rocket-pool/smartnode/bindings/tests" + "github.com/rocket-pool/smartnode/bindings/tests/testutils" "github.com/rocket-pool/smartnode/bindings/tests/testutils/accounts" ) var ( - client *ethclient.Client + client *testutils.EthClientWrapper rp *rocketpool.RocketPool ownerAccount *accounts.Account @@ -27,10 +28,11 @@ func TestMain(m *testing.M) { var err error // Initialize eth client - client, err = ethclient.Dial(tests.Eth1ProviderAddress) + rawClient, err := ethclient.Dial(tests.Eth1ProviderAddress) if err != nil { log.Fatal(err) } + client = testutils.NewEthClientWrapper(rawClient) // Initialize contract manager rp, err = rocketpool.NewRocketPool(client, common.HexToAddress(tests.RocketStorageAddress)) diff --git a/bindings/tests/rocketpool/main_test.go b/bindings/tests/rocketpool/main_test.go index 07d0e61c4..94b8dcb95 100644 --- a/bindings/tests/rocketpool/main_test.go +++ b/bindings/tests/rocketpool/main_test.go @@ -11,10 +11,11 @@ import ( "github.com/rocket-pool/smartnode/bindings/rocketpool" "github.com/rocket-pool/smartnode/bindings/tests" + "github.com/rocket-pool/smartnode/bindings/tests/testutils" ) var ( - client *ethclient.Client + client *testutils.EthClientWrapper rp *rocketpool.RocketPool ) @@ -22,10 +23,11 @@ func TestMain(m *testing.M) { var err error // Initialize eth client - client, err = ethclient.Dial(tests.Eth1ProviderAddress) + rawClient, err := ethclient.Dial(tests.Eth1ProviderAddress) if err != nil { log.Fatal(err) } + client = testutils.NewEthClientWrapper(rawClient) // Initialize contract manager rp, err = rocketpool.NewRocketPool(client, common.HexToAddress(tests.RocketStorageAddress)) diff --git a/bindings/tests/rocketpool/rocketpool_test.go b/bindings/tests/rocketpool/rocketpool_test.go index 4c23c15be..1f66b30a6 100644 --- a/bindings/tests/rocketpool/rocketpool_test.go +++ b/bindings/tests/rocketpool/rocketpool_test.go @@ -11,7 +11,7 @@ import ( func TestGetAddress(t *testing.T) { // Get contract address - address1, err := rp.GetAddress("rocketDepositPool") + address1, err := rp.GetAddress("rocketDepositPool", nil) if err != nil { t.Fatalf("error getting contract address: %s", err) } else if bytes.Equal(address1.Bytes(), common.Address{}.Bytes()) { @@ -19,7 +19,7 @@ func TestGetAddress(t *testing.T) { } // Get cached contract address - address2, err := rp.GetAddress("rocketDepositPool") + address2, err := rp.GetAddress("rocketDepositPool", nil) if err != nil { t.Fatalf("error getting cached contract address: %s", err) } else if !bytes.Equal(address2.Bytes(), address1.Bytes()) { @@ -31,7 +31,7 @@ func TestGetAddress(t *testing.T) { func TestGetAddresses(t *testing.T) { // Get contract addresses - addresses1, err := rp.GetAddresses("rocketNodeManager", "rocketNodeDeposit") + addresses1, err := rp.GetAddresses(nil, "rocketNodeManager", "rocketNodeDeposit") if err != nil { t.Fatalf("error getting contract addresses: %s", err) } else { @@ -43,7 +43,7 @@ func TestGetAddresses(t *testing.T) { } // Get cached contract addresses - addresses2, err := rp.GetAddresses("rocketNodeManager", "rocketNodeDeposit") + addresses2, err := rp.GetAddresses(nil, "rocketNodeManager", "rocketNodeDeposit") if err != nil { t.Fatalf("error getting cached contract addresses: %s", err) } else { @@ -59,13 +59,13 @@ func TestGetAddresses(t *testing.T) { func TestGetABI(t *testing.T) { // Get ABI - abi1, err := rp.GetABI("rocketDepositPool") + abi1, err := rp.GetABI("rocketDepositPool", nil) if err != nil { t.Fatalf("error getting contract ABI: %s", err) } // Get cached ABI - abi2, err := rp.GetABI("rocketDepositPool") + abi2, err := rp.GetABI("rocketDepositPool", nil) if err != nil { t.Fatalf("error getting cached contract ABI: %s", err) } else { @@ -87,13 +87,13 @@ func TestGetABI(t *testing.T) { func TestGetABIs(t *testing.T) { // Get ABIs - abis1, err := rp.GetABIs("rocketNodeManager", "rocketNodeDeposit") + abis1, err := rp.GetABIs(nil, "rocketNodeManager", "rocketNodeDeposit") if err != nil { t.Fatalf("error getting contract ABIs: %s", err) } // Get cached ABIs - abis2, err := rp.GetABIs("rocketNodeManager", "rocketNodeDeposit") + abis2, err := rp.GetABIs(nil, "rocketNodeManager", "rocketNodeDeposit") if err != nil { t.Fatalf("error getting cached contract ABIs: %s", err) } else { @@ -117,12 +117,12 @@ func TestGetABIs(t *testing.T) { func TestGetContract(t *testing.T) { // Get contract - if _, err := rp.GetContract("rocketDepositPool"); err != nil { + if _, err := rp.GetContract("rocketDepositPool", nil); err != nil { t.Fatalf("error getting contract: %s", err) } // Get cached contract - if _, err := rp.GetContract("rocketDepositPool"); err != nil { + if _, err := rp.GetContract("rocketDepositPool", nil); err != nil { t.Fatalf("error getting cached contract: %s", err) } @@ -131,12 +131,12 @@ func TestGetContract(t *testing.T) { func TestGetContracts(t *testing.T) { // Get contracts - if _, err := rp.GetContracts("rocketNodeManager", "rocketNodeDeposit"); err != nil { + if _, err := rp.GetContracts(nil, "rocketNodeManager", "rocketNodeDeposit"); err != nil { t.Fatalf("error getting contracts: %s", err) } // Get cached contracts - if _, err := rp.GetContracts("rocketNodeManager", "rocketNodeDeposit"); err != nil { + if _, err := rp.GetContracts(nil, "rocketNodeManager", "rocketNodeDeposit"); err != nil { t.Fatalf("error getting cached contracts: %s", err) } @@ -145,12 +145,12 @@ func TestGetContracts(t *testing.T) { func TestMakeContract(t *testing.T) { // Make contract - if _, err := rp.MakeContract("rocketMinipool", common.HexToAddress("0x1111111111111111111111111111111111111111")); err != nil { + if _, err := rp.MakeContract("rocketMinipool", common.HexToAddress("0x1111111111111111111111111111111111111111"), nil); err != nil { t.Fatalf("error making contract: %s", err) } // Make contract with cached ABI - if _, err := rp.MakeContract("rocketMinipool", common.HexToAddress("0x2222222222222222222222222222222222222222")); err != nil { + if _, err := rp.MakeContract("rocketMinipool", common.HexToAddress("0x2222222222222222222222222222222222222222"), nil); err != nil { t.Fatalf("error making contract with cached ABI: %s", err) } diff --git a/bindings/tests/settings/protocol/main_test.go b/bindings/tests/settings/protocol/main_test.go index 4b5d546f4..c90556fe8 100644 --- a/bindings/tests/settings/protocol/main_test.go +++ b/bindings/tests/settings/protocol/main_test.go @@ -11,11 +11,12 @@ import ( "github.com/rocket-pool/smartnode/bindings/rocketpool" "github.com/rocket-pool/smartnode/bindings/tests" + "github.com/rocket-pool/smartnode/bindings/tests/testutils" "github.com/rocket-pool/smartnode/bindings/tests/testutils/accounts" ) var ( - client *ethclient.Client + client *testutils.EthClientWrapper rp *rocketpool.RocketPool ownerAccount *accounts.Account @@ -25,10 +26,11 @@ func TestMain(m *testing.M) { var err error // Initialize eth client - client, err = ethclient.Dial(tests.Eth1ProviderAddress) + rawClient, err := ethclient.Dial(tests.Eth1ProviderAddress) if err != nil { log.Fatal(err) } + client = testutils.NewEthClientWrapper(rawClient) // Initialize contract manager rp, err = rocketpool.NewRocketPool(client, common.HexToAddress(tests.RocketStorageAddress)) diff --git a/bindings/tests/settings/trustednode/main_test.go b/bindings/tests/settings/trustednode/main_test.go index 374b1c344..3132ebbad 100644 --- a/bindings/tests/settings/trustednode/main_test.go +++ b/bindings/tests/settings/trustednode/main_test.go @@ -11,11 +11,12 @@ import ( "github.com/rocket-pool/smartnode/bindings/rocketpool" "github.com/rocket-pool/smartnode/bindings/tests" + "github.com/rocket-pool/smartnode/bindings/tests/testutils" "github.com/rocket-pool/smartnode/bindings/tests/testutils/accounts" ) var ( - client *ethclient.Client + client *testutils.EthClientWrapper rp *rocketpool.RocketPool ownerAccount *accounts.Account @@ -28,10 +29,11 @@ func TestMain(m *testing.M) { var err error // Initialize eth client - client, err = ethclient.Dial(tests.Eth1ProviderAddress) + rawClient, err := ethclient.Dial(tests.Eth1ProviderAddress) if err != nil { log.Fatal(err) } + client = testutils.NewEthClientWrapper(rawClient) // Initialize contract manager rp, err = rocketpool.NewRocketPool(client, common.HexToAddress(tests.RocketStorageAddress)) diff --git a/bindings/tests/testutils/auction/auction.go b/bindings/tests/testutils/auction/auction.go index 2a840ae55..c072f1951 100644 --- a/bindings/tests/testutils/auction/auction.go +++ b/bindings/tests/testutils/auction/auction.go @@ -60,10 +60,10 @@ func CreateSlashedRPL(t *testing.T, rp *rocketpool.RocketPool, ownerAccount *acc } // Mark minipool as withdrawable with zero end balance - if _, err := minipool.SubmitMinipoolWithdrawable(rp, mp.Address, trustedNodeAccount.GetTransactor()); err != nil { + if _, err := minipool.SubmitMinipoolWithdrawable(rp, mp.GetAddress(), trustedNodeAccount.GetTransactor()); err != nil { return err } - if _, err := minipool.SubmitMinipoolWithdrawable(rp, mp.Address, trustedNodeAccount2.GetTransactor()); err != nil { + if _, err := minipool.SubmitMinipoolWithdrawable(rp, mp.GetAddress(), trustedNodeAccount2.GetTransactor()); err != nil { return err } diff --git a/bindings/tests/testutils/eth_client_wrapper.go b/bindings/tests/testutils/eth_client_wrapper.go new file mode 100644 index 000000000..0142d7e14 --- /dev/null +++ b/bindings/tests/testutils/eth_client_wrapper.go @@ -0,0 +1,126 @@ +package testutils + +import ( + "context" + "math/big" + "time" + + "github.com/ethereum/go-ethereum" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/ethclient" +) + +// EthClientWrapper wraps *ethclient.Client to implement the ExecutionClient interface +type EthClientWrapper struct { + *ethclient.Client +} + +// NewEthClientWrapper creates a new wrapper around an ethclient.Client +func NewEthClientWrapper(client *ethclient.Client) *EthClientWrapper { + return &EthClientWrapper{Client: client} +} + +// LatestBlockTime returns the timestamp of the latest block +func (w *EthClientWrapper) LatestBlockTime(ctx context.Context) (time.Time, error) { + header, err := w.Client.HeaderByNumber(ctx, nil) + if err != nil { + return time.Time{}, err + } + return time.Unix(int64(header.Time), 0), nil +} + +// CodeAt returns the code of the given account +func (w *EthClientWrapper) CodeAt(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error) { + return w.Client.CodeAt(ctx, contract, blockNumber) +} + +// CallContract executes an Ethereum contract call +func (w *EthClientWrapper) CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) { + return w.Client.CallContract(ctx, call, blockNumber) +} + +// HeaderByHash returns the block header with the given hash +func (w *EthClientWrapper) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) { + return w.Client.HeaderByHash(ctx, hash) +} + +// HeaderByNumber returns a block header from the current canonical chain +func (w *EthClientWrapper) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) { + return w.Client.HeaderByNumber(ctx, number) +} + +// PendingCodeAt returns the code of the given account in the pending state +func (w *EthClientWrapper) PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error) { + return w.Client.PendingCodeAt(ctx, account) +} + +// PendingNonceAt retrieves the current pending nonce associated with an account +func (w *EthClientWrapper) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error) { + return w.Client.PendingNonceAt(ctx, account) +} + +// SuggestGasPrice retrieves the currently suggested gas price +func (w *EthClientWrapper) SuggestGasPrice(ctx context.Context) (*big.Int, error) { + return w.Client.SuggestGasPrice(ctx) +} + +// SuggestGasTipCap retrieves the currently suggested 1559 priority fee +func (w *EthClientWrapper) SuggestGasTipCap(ctx context.Context) (*big.Int, error) { + return w.Client.SuggestGasTipCap(ctx) +} + +// EstimateGas tries to estimate the gas needed to execute a specific transaction +func (w *EthClientWrapper) EstimateGas(ctx context.Context, call ethereum.CallMsg) (gas uint64, err error) { + return w.Client.EstimateGas(ctx, call) +} + +// SendTransaction injects the transaction into the pending pool for execution +func (w *EthClientWrapper) SendTransaction(ctx context.Context, tx *types.Transaction) error { + return w.Client.SendTransaction(ctx, tx) +} + +// FilterLogs executes a log filter operation +func (w *EthClientWrapper) FilterLogs(ctx context.Context, query ethereum.FilterQuery) ([]types.Log, error) { + return w.Client.FilterLogs(ctx, query) +} + +// SubscribeFilterLogs creates a background log filtering operation +func (w *EthClientWrapper) SubscribeFilterLogs(ctx context.Context, query ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error) { + return w.Client.SubscribeFilterLogs(ctx, query, ch) +} + +// TransactionReceipt returns the receipt of a transaction by transaction hash +func (w *EthClientWrapper) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) { + return w.Client.TransactionReceipt(ctx, txHash) +} + +// BlockNumber returns the most recent block number +func (w *EthClientWrapper) BlockNumber(ctx context.Context) (uint64, error) { + return w.Client.BlockNumber(ctx) +} + +// BalanceAt returns the wei balance of the given account +func (w *EthClientWrapper) BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error) { + return w.Client.BalanceAt(ctx, account, blockNumber) +} + +// TransactionByHash returns the transaction with the given hash +func (w *EthClientWrapper) TransactionByHash(ctx context.Context, hash common.Hash) (tx *types.Transaction, isPending bool, err error) { + return w.Client.TransactionByHash(ctx, hash) +} + +// NonceAt returns the account nonce of the given account +func (w *EthClientWrapper) NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error) { + return w.Client.NonceAt(ctx, account, blockNumber) +} + +// SyncProgress retrieves the current progress of the sync algorithm +func (w *EthClientWrapper) SyncProgress(ctx context.Context) (*ethereum.SyncProgress, error) { + return w.Client.SyncProgress(ctx) +} + +// ChainID retrieves the current chain ID +func (w *EthClientWrapper) ChainID(ctx context.Context) (*big.Int, error) { + return w.Client.ChainID(ctx) +} diff --git a/bindings/tests/testutils/minipool/minipool.go b/bindings/tests/testutils/minipool/minipool.go index 31253f203..6b2e92107 100644 --- a/bindings/tests/testutils/minipool/minipool.go +++ b/bindings/tests/testutils/minipool/minipool.go @@ -27,7 +27,7 @@ type minipoolCreated struct { } // Create a minipool -func CreateMinipool(t *testing.T, rp *rocketpool.RocketPool, ownerAccount, nodeAccount *accounts.Account, depositAmount *big.Int, pubkey int) (*minipool.Minipool, error) { +func CreateMinipool(t *testing.T, rp *rocketpool.RocketPool, ownerAccount, nodeAccount *accounts.Account, depositAmount *big.Int, pubkey int) (minipool.Minipool, error) { // Mint & stake RPL required for mininpool rplRequired, err := GetMinipoolRPLRequired(rp) @@ -45,7 +45,7 @@ func CreateMinipool(t *testing.T, rp *rocketpool.RocketPool, ownerAccount, nodeA } // Get minipool manager contract - rocketMinipoolManager, err := rp.GetContract("rocketMinipoolManager") + rocketMinipoolManager, err := rp.GetContract("rocketMinipoolManager", nil) if err != nil { return nil, err } @@ -63,19 +63,19 @@ func CreateMinipool(t *testing.T, rp *rocketpool.RocketPool, ownerAccount, nodeA } // Return minipool instance - return minipool.NewMinipool(rp, minipoolAddress) + return minipool.NewMinipool(rp, minipoolAddress, nil) } // Stake a minipool -func StakeMinipool(rp *rocketpool.RocketPool, mp *minipool.Minipool, nodeAccount *accounts.Account) error { +func StakeMinipool(rp *rocketpool.RocketPool, mp minipool.Minipool, nodeAccount *accounts.Account) error { // Get validator & deposit data validatorPubkey, err := validator.GetValidatorPubkey(1) if err != nil { return err } - withdrawalCredentials, err := minipool.GetMinipoolWithdrawalCredentials(rp, mp.Address, nil) + withdrawalCredentials, err := minipool.GetMinipoolWithdrawalCredentials(rp, mp.GetAddress(), nil) if err != nil { return err } diff --git a/bindings/tests/testutils/node/node.go b/bindings/tests/testutils/node/node.go index 4d62a87a6..e502bd58c 100644 --- a/bindings/tests/testutils/node/node.go +++ b/bindings/tests/testutils/node/node.go @@ -1,9 +1,6 @@ package node import ( - "fmt" - - trustednodedao "github.com/rocket-pool/smartnode/bindings/dao/trustednode" "github.com/rocket-pool/smartnode/bindings/node" "github.com/rocket-pool/smartnode/bindings/rocketpool" trustednodesettings "github.com/rocket-pool/smartnode/bindings/settings/trustednode" @@ -17,6 +14,9 @@ import ( var trustedNodeIndex = 0 // Register a trusted node +// NOTE: This function is commented out because trustednodedao.BootstrapMember is no longer available +// If you need this functionality, you'll need to update it to use the new API +/* func RegisterTrustedNode(rp *rocketpool.RocketPool, ownerAccount *accounts.Account, trustedNodeAccount *accounts.Account) error { // Register node @@ -44,6 +44,7 @@ func RegisterTrustedNode(rp *rocketpool.RocketPool, ownerAccount *accounts.Accou return nil } +*/ // Mint trusted node DAO RPL bond to a node account and approve it for spending func MintTrustedNodeBond(rp *rocketpool.RocketPool, ownerAccount *accounts.Account, trustedNodeAccount *accounts.Account) error { @@ -55,7 +56,7 @@ func MintTrustedNodeBond(rp *rocketpool.RocketPool, ownerAccount *accounts.Accou } // Get RocketDAONodeTrustedActions contract address - rocketDAONodeTrustedActionsAddress, err := rp.GetAddress("rocketDAONodeTrustedActions") + rocketDAONodeTrustedActionsAddress, err := rp.GetAddress("rocketDAONodeTrustedActions", nil) if err != nil { return err } @@ -72,3 +73,7 @@ func MintTrustedNodeBond(rp *rocketpool.RocketPool, ownerAccount *accounts.Accou return nil } + +// Suppress unused import warnings +var _ = node.RegisterNode +var _ = trustednodesettings.GetRPLBond diff --git a/bindings/tests/testutils/node/staking.go b/bindings/tests/testutils/node/staking.go index 3a5fb5c27..b2e50a840 100644 --- a/bindings/tests/testutils/node/staking.go +++ b/bindings/tests/testutils/node/staking.go @@ -15,7 +15,7 @@ import ( func StakeRPL(rp *rocketpool.RocketPool, ownerAccount, nodeAccount *accounts.Account, amount *big.Int) error { // Get RocketNodeStaking contract address - rocketNodeStakingAddress, err := rp.GetAddress("rocketNodeStaking") + rocketNodeStakingAddress, err := rp.GetAddress("rocketNodeStaking", nil) if err != nil { return err } diff --git a/bindings/tests/testutils/tokens/rpl/rpl.go b/bindings/tests/testutils/tokens/rpl/rpl.go index 0c8d28859..076ba36df 100644 --- a/bindings/tests/testutils/tokens/rpl/rpl.go +++ b/bindings/tests/testutils/tokens/rpl/rpl.go @@ -14,7 +14,7 @@ import ( func MintRPL(rp *rocketpool.RocketPool, ownerAccount *accounts.Account, toAccount *accounts.Account, amount *big.Int) error { // Get RPL token contract address - rocketTokenRPLAddress, err := rp.GetAddress("rocketTokenRPL") + rocketTokenRPLAddress, err := rp.GetAddress("rocketTokenRPL", nil) if err != nil { return err } @@ -37,7 +37,7 @@ func MintRPL(rp *rocketpool.RocketPool, ownerAccount *accounts.Account, toAccoun // Mint an amount of fixed-supply RPL to an account func MintFixedSupplyRPL(rp *rocketpool.RocketPool, ownerAccount *accounts.Account, toAccount *accounts.Account, amount *big.Int) error { - rocketTokenFixedSupplyRPL, err := rp.GetContract("rocketTokenRPLFixedSupply") + rocketTokenFixedSupplyRPL, err := rp.GetContract("rocketTokenRPLFixedSupply", nil) if err != nil { return err } diff --git a/bindings/tests/tokens/main_test.go b/bindings/tests/tokens/main_test.go index afabedf65..4c00ec748 100644 --- a/bindings/tests/tokens/main_test.go +++ b/bindings/tests/tokens/main_test.go @@ -11,11 +11,12 @@ import ( "github.com/rocket-pool/smartnode/bindings/rocketpool" "github.com/rocket-pool/smartnode/bindings/tests" + "github.com/rocket-pool/smartnode/bindings/tests/testutils" "github.com/rocket-pool/smartnode/bindings/tests/testutils/accounts" ) var ( - client *ethclient.Client + client *testutils.EthClientWrapper rp *rocketpool.RocketPool ownerAccount *accounts.Account @@ -29,10 +30,11 @@ func TestMain(m *testing.M) { var err error // Initialize eth client - client, err = ethclient.Dial(tests.Eth1ProviderAddress) + rawClient, err := ethclient.Dial(tests.Eth1ProviderAddress) if err != nil { log.Fatal(err) } + client = testutils.NewEthClientWrapper(rawClient) // Initialize contract manager rp, err = rocketpool.NewRocketPool(client, common.HexToAddress(tests.RocketStorageAddress)) diff --git a/bindings/tests/tokens/rpl_test.go b/bindings/tests/tokens/rpl_test.go index 5515a239e..47634fecf 100644 --- a/bindings/tests/tokens/rpl_test.go +++ b/bindings/tests/tokens/rpl_test.go @@ -195,7 +195,7 @@ func TestSwapFixedSupplyRPLForRPL(t *testing.T) { } // Approve fixed-supply RPL spend - rocketTokenRPLAddress, err := rp.GetAddress("rocketTokenRPL") + rocketTokenRPLAddress, err := rp.GetAddress("rocketTokenRPL", nil) if err != nil { t.Fatal(err) } diff --git a/rocketpool/watchtower/utils/utils_test.go b/rocketpool/watchtower/utils/utils_test.go index f055830e6..5cbe256d3 100644 --- a/rocketpool/watchtower/utils/utils_test.go +++ b/rocketpool/watchtower/utils/utils_test.go @@ -46,3 +46,22 @@ func TestFindNextSubmission(t *testing.T) { t.Fatalf("Should have error when using a reference date in the future") } } + +func FindNextSubmissionTimestamp(latestBlockTimestamp int64, referenceTimestamp int64, submissionIntervalInSeconds int64) (int64, error) { + if latestBlockTimestamp == 0 || referenceTimestamp == 0 || submissionIntervalInSeconds == 0 { + return 0, fmt.Errorf("FindNextSubmissionTimestamp can't use zero values") + } + + // Calculate the difference between latestBlockTime and the reference timestamp + timeDifference := latestBlockTimestamp - referenceTimestamp + if timeDifference < 0 { + return 0, fmt.Errorf("FindNextSubmissionTimestamp referenceTimestamp in the future") + } + + // Calculate the remainder to find out how far off from a multiple of the interval the current time is + remainder := timeDifference % submissionIntervalInSeconds + + // Subtract the remainder from current time to find the first multiple of the interval in the past + submissionTimeRef := latestBlockTimestamp - remainder + return submissionTimeRef, nil +} diff --git a/shared/services/rewards/mock_v11_test.go b/shared/services/rewards/mock_v11_test.go index f9ce2b329..fda92d838 100644 --- a/shared/services/rewards/mock_v11_test.go +++ b/shared/services/rewards/mock_v11_test.go @@ -7,13 +7,13 @@ package rewards import ( "fmt" "math/big" - "strconv" "strings" "testing" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/fatih/color" + rptypes "github.com/rocket-pool/smartnode/bindings/types" "github.com/rocket-pool/smartnode/bindings/utils/eth" "github.com/rocket-pool/smartnode/shared/services/beacon" "github.com/rocket-pool/smartnode/shared/services/rewards/test" @@ -55,7 +55,9 @@ func TestMockIntervalDefaultsTreegenv11(tt *testing.T) { t.bc.SetMinipoolPerformance(validator.Index, make([]uint64, 0)) } for _, validator := range state.MegapoolValidatorGlobalIndex { - t.bc.SetMinipoolPerformance(strconv.Itoa(int(validator.ValidatorInfo.ValidatorIndex)), make([]uint64, 0)) + pubkey := rptypes.BytesToValidatorPubkey(validator.Pubkey) + details := state.MegapoolValidatorDetails[pubkey] + t.bc.SetMinipoolPerformance(details.Index, make([]uint64, 0)) } // Set some custom balances for the validators that opt in and out of smoothing pool diff --git a/shared/services/rewards/test/beacon.go b/shared/services/rewards/test/beacon.go index fdcfb3c81..6c380cca2 100644 --- a/shared/services/rewards/test/beacon.go +++ b/shared/services/rewards/test/beacon.go @@ -119,11 +119,16 @@ func (m *MockBeaconClient) SetState(state *state.NetworkState) { m.validatorPubkeys[validatorIndex(v.Index)] = v.Pubkey } for _, v := range state.MegapoolValidatorGlobalIndex { - vIndex := strconv.FormatUint(v.ValidatorInfo.ValidatorIndex, 10) + pubkey := types.BytesToValidatorPubkey(v.Pubkey) + details, ok := state.MegapoolValidatorDetails[pubkey] + if !ok { + continue + } + vIndex := details.Index if _, ok := m.validatorPubkeys[validatorIndex(vIndex)]; ok { m.t.Fatalf("Validator %s already set", vIndex) } - m.validatorPubkeys[validatorIndex(vIndex)] = types.ValidatorPubkey(v.Pubkey) + m.validatorPubkeys[validatorIndex(vIndex)] = pubkey } } diff --git a/shared/services/rewards/test/mock.go b/shared/services/rewards/test/mock.go index 04996ef5c..a0db5cb7f 100644 --- a/shared/services/rewards/test/mock.go +++ b/shared/services/rewards/test/mock.go @@ -872,8 +872,7 @@ func (h *MockHistory) GetEndNetworkState() *state.NetworkState { vifgi := megapool.ValidatorInfoFromGlobalIndex{ Pubkey: pubkey.Bytes(), ValidatorInfo: megapool.ValidatorInfo{ - ValidatorIndex: intIdx, - Staked: true, + Staked: true, }, MegapoolAddress: node.MegapoolAddress(), ValidatorId: uint32(intIdx),