Skip to content

Commit

Permalink
accounts/abi: don't use the deprecated, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusVanDerWijden committed Jan 2, 2024
1 parent 9c754a0 commit 12c05b9
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions accounts/abi/bind/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import (
"time"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient/simulated"
"github.com/ethereum/go-ethereum/params"
)

Expand All @@ -53,11 +53,10 @@ var waitDeployedTests = map[string]struct {
},
}

//nolint:staticcheck
func TestWaitDeployed(t *testing.T) {
t.Parallel()
for name, test := range waitDeployedTests {
backend := backends.NewSimulatedBackend(
backend := simulated.New(
core.GenesisAlloc{
crypto.PubkeyToAddress(testKey.PublicKey): {Balance: big.NewInt(10000000000000000)},
},
Expand All @@ -66,7 +65,7 @@ func TestWaitDeployed(t *testing.T) {
defer backend.Close()

// Create the transaction
head, _ := backend.HeaderByNumber(context.Background(), nil) // Should be child's, good enough
head, _ := backend.Client().HeaderByNumber(context.Background(), nil) // Should be child's, good enough
gasPrice := new(big.Int).Add(head.BaseFee, big.NewInt(1))

tx := types.NewContractCreation(0, big.NewInt(0), test.gas, gasPrice, common.FromHex(test.code))
Expand All @@ -80,12 +79,12 @@ func TestWaitDeployed(t *testing.T) {
ctx = context.Background()
)
go func() {
address, err = bind.WaitDeployed(ctx, backend, tx)
address, err = bind.WaitDeployed(ctx, backend.Client(), tx)
close(mined)
}()

// Send and mine the transaction.
backend.SendTransaction(ctx, tx)
backend.Client().SendTransaction(ctx, tx)
backend.Commit()

select {
Expand All @@ -102,17 +101,16 @@ func TestWaitDeployed(t *testing.T) {
}
}

//nolint:staticcheck
func TestWaitDeployedCornerCases(t *testing.T) {
backend := backends.NewSimulatedBackend(
backend := simulated.New(
core.GenesisAlloc{
crypto.PubkeyToAddress(testKey.PublicKey): {Balance: big.NewInt(10000000000000000)},
},
10000000,
)
defer backend.Close()

head, _ := backend.HeaderByNumber(context.Background(), nil) // Should be child's, good enough
head, _ := backend.Client().HeaderByNumber(context.Background(), nil) // Should be child's, good enough
gasPrice := new(big.Int).Add(head.BaseFee, big.NewInt(1))

// Create a transaction to an account.
Expand All @@ -121,10 +119,10 @@ func TestWaitDeployedCornerCases(t *testing.T) {
tx, _ = types.SignTx(tx, types.LatestSigner(params.AllDevChainProtocolChanges), testKey)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
backend.SendTransaction(ctx, tx)
backend.Client().SendTransaction(ctx, tx)
backend.Commit()
notContractCreation := errors.New("tx is not contract creation")
if _, err := bind.WaitDeployed(ctx, backend, tx); err.Error() != notContractCreation.Error() {
if _, err := bind.WaitDeployed(ctx, backend.Client(), tx); err.Error() != notContractCreation.Error() {
t.Errorf("error mismatch: want %q, got %q, ", notContractCreation, err)
}

Expand All @@ -134,11 +132,11 @@ func TestWaitDeployedCornerCases(t *testing.T) {

go func() {
contextCanceled := errors.New("context canceled")
if _, err := bind.WaitDeployed(ctx, backend, tx); err.Error() != contextCanceled.Error() {
if _, err := bind.WaitDeployed(ctx, backend.Client(), tx); err.Error() != contextCanceled.Error() {
t.Errorf("error mismatch: want %q, got %q, ", contextCanceled, err)
}
}()

backend.SendTransaction(ctx, tx)
backend.Client().SendTransaction(ctx, tx)
cancel()
}

0 comments on commit 12c05b9

Please sign in to comment.