From eb90b2899f4bb23037d19aa66611aa65ef9219b0 Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Tue, 14 Jan 2025 10:56:07 +0800 Subject: [PATCH] backends: increase gaslimit in order to allow tests of large contracts (#17358) --- accounts/abi/bind/backends/simulated.go | 5 +++-- contracts/randomize/randomize_test.go | 2 +- contracts/tests/Inherited_test.go | 9 +++++---- contracts/trc21issuer/trc21issuer_test.go | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/accounts/abi/bind/backends/simulated.go b/accounts/abi/bind/backends/simulated.go index ea79ab4484..15d7edc7e1 100644 --- a/accounts/abi/bind/backends/simulated.go +++ b/accounts/abi/bind/backends/simulated.go @@ -141,10 +141,11 @@ func NewXDCSimulatedBackend(alloc core.GenesisAlloc, gasLimit uint64, chainConfi // NewSimulatedBackend creates a new binding backend using a simulated blockchain // for testing purposes. +// // A simulated backend always uses chainID 1337. -func NewSimulatedBackend(alloc core.GenesisAlloc) *SimulatedBackend { +func NewSimulatedBackend(alloc core.GenesisAlloc, gasLimit uint64) *SimulatedBackend { database := rawdb.NewMemoryDatabase() - genesis := core.Genesis{Config: params.AllEthashProtocolChanges, Alloc: alloc, GasLimit: 42000000} + genesis := core.Genesis{Config: params.AllEthashProtocolChanges, GasLimit: gasLimit, Alloc: alloc} genesis.MustCommit(database) blockchain, _ := core.NewBlockChain(database, nil, genesis.Config, ethash.NewFaker(), vm.Config{}) diff --git a/contracts/randomize/randomize_test.go b/contracts/randomize/randomize_test.go index 14d229196c..fd117681f1 100644 --- a/contracts/randomize/randomize_test.go +++ b/contracts/randomize/randomize_test.go @@ -73,7 +73,7 @@ func TestRandomize(t *testing.T) { func TestSendTxRandomizeSecretAndOpening(t *testing.T) { genesis := core.GenesisAlloc{acc1Addr: {Balance: big.NewInt(1000000000000)}} - backend := backends.NewSimulatedBackend(genesis) + backend := backends.NewSimulatedBackend(genesis, 42000000) backend.Commit() signer := types.HomesteadSigner{} ctx := context.Background() diff --git a/contracts/tests/Inherited_test.go b/contracts/tests/Inherited_test.go index 94298fc0e3..a60fa6344f 100644 --- a/contracts/tests/Inherited_test.go +++ b/contracts/tests/Inherited_test.go @@ -2,15 +2,16 @@ package tests import ( "fmt" + "math/big" + "os" + "testing" + "github.com/XinFinOrg/XDPoSChain/accounts/abi/bind" "github.com/XinFinOrg/XDPoSChain/accounts/abi/bind/backends" "github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/core" "github.com/XinFinOrg/XDPoSChain/crypto" "github.com/XinFinOrg/XDPoSChain/log" - "math/big" - "os" - "testing" ) var ( @@ -27,7 +28,7 @@ func TestPriceFeed(t *testing.T) { // init genesis contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{ mainAddr: {Balance: big.NewInt(0).Mul(big.NewInt(10000000000000), big.NewInt(10000000000000))}, - }) + }, 42000000) transactOpts := bind.NewKeyedTransactor(mainKey) // deploy payer swap SMC addr, contract, err := DeployMyInherited(transactOpts, contractBackend) diff --git a/contracts/trc21issuer/trc21issuer_test.go b/contracts/trc21issuer/trc21issuer_test.go index a8658b105b..aeebb7b7ad 100644 --- a/contracts/trc21issuer/trc21issuer_test.go +++ b/contracts/trc21issuer/trc21issuer_test.go @@ -33,7 +33,7 @@ func TestFeeTxWithTRC21Token(t *testing.T) { // init genesis contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{ mainAddr: {Balance: big.NewInt(0).Mul(big.NewInt(10000000000000), big.NewInt(10000000000000))}, - }) + }, 42000000) transactOpts := bind.NewKeyedTransactor(mainKey) // deploy payer swap SMC trc21IssuerAddr, trc21Issuer, err := DeployTRC21Issuer(transactOpts, contractBackend, minApply)