backends: increase gaslimit in order to allow tests of large contracts (#17358)

This commit is contained in:
Daniel Liu 2025-01-14 10:56:07 +08:00
parent 165510daef
commit eb90b2899f
4 changed files with 10 additions and 8 deletions

View file

@ -141,10 +141,11 @@ func NewXDCSimulatedBackend(alloc core.GenesisAlloc, gasLimit uint64, chainConfi
// NewSimulatedBackend creates a new binding backend using a simulated blockchain // NewSimulatedBackend creates a new binding backend using a simulated blockchain
// for testing purposes. // for testing purposes.
//
// A simulated backend always uses chainID 1337. // A simulated backend always uses chainID 1337.
func NewSimulatedBackend(alloc core.GenesisAlloc) *SimulatedBackend { func NewSimulatedBackend(alloc core.GenesisAlloc, gasLimit uint64) *SimulatedBackend {
database := rawdb.NewMemoryDatabase() 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) genesis.MustCommit(database)
blockchain, _ := core.NewBlockChain(database, nil, genesis.Config, ethash.NewFaker(), vm.Config{}) blockchain, _ := core.NewBlockChain(database, nil, genesis.Config, ethash.NewFaker(), vm.Config{})

View file

@ -73,7 +73,7 @@ func TestRandomize(t *testing.T) {
func TestSendTxRandomizeSecretAndOpening(t *testing.T) { func TestSendTxRandomizeSecretAndOpening(t *testing.T) {
genesis := core.GenesisAlloc{acc1Addr: {Balance: big.NewInt(1000000000000)}} genesis := core.GenesisAlloc{acc1Addr: {Balance: big.NewInt(1000000000000)}}
backend := backends.NewSimulatedBackend(genesis) backend := backends.NewSimulatedBackend(genesis, 42000000)
backend.Commit() backend.Commit()
signer := types.HomesteadSigner{} signer := types.HomesteadSigner{}
ctx := context.Background() ctx := context.Background()

View file

@ -2,15 +2,16 @@ package tests
import ( import (
"fmt" "fmt"
"math/big"
"os"
"testing"
"github.com/XinFinOrg/XDPoSChain/accounts/abi/bind" "github.com/XinFinOrg/XDPoSChain/accounts/abi/bind"
"github.com/XinFinOrg/XDPoSChain/accounts/abi/bind/backends" "github.com/XinFinOrg/XDPoSChain/accounts/abi/bind/backends"
"github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/core" "github.com/XinFinOrg/XDPoSChain/core"
"github.com/XinFinOrg/XDPoSChain/crypto" "github.com/XinFinOrg/XDPoSChain/crypto"
"github.com/XinFinOrg/XDPoSChain/log" "github.com/XinFinOrg/XDPoSChain/log"
"math/big"
"os"
"testing"
) )
var ( var (
@ -27,7 +28,7 @@ func TestPriceFeed(t *testing.T) {
// init genesis // init genesis
contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{ contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{
mainAddr: {Balance: big.NewInt(0).Mul(big.NewInt(10000000000000), big.NewInt(10000000000000))}, mainAddr: {Balance: big.NewInt(0).Mul(big.NewInt(10000000000000), big.NewInt(10000000000000))},
}) }, 42000000)
transactOpts := bind.NewKeyedTransactor(mainKey) transactOpts := bind.NewKeyedTransactor(mainKey)
// deploy payer swap SMC // deploy payer swap SMC
addr, contract, err := DeployMyInherited(transactOpts, contractBackend) addr, contract, err := DeployMyInherited(transactOpts, contractBackend)

View file

@ -33,7 +33,7 @@ func TestFeeTxWithTRC21Token(t *testing.T) {
// init genesis // init genesis
contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{ contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{
mainAddr: {Balance: big.NewInt(0).Mul(big.NewInt(10000000000000), big.NewInt(10000000000000))}, mainAddr: {Balance: big.NewInt(0).Mul(big.NewInt(10000000000000), big.NewInt(10000000000000))},
}) }, 42000000)
transactOpts := bind.NewKeyedTransactor(mainKey) transactOpts := bind.NewKeyedTransactor(mainKey)
// deploy payer swap SMC // deploy payer swap SMC
trc21IssuerAddr, trc21Issuer, err := DeployTRC21Issuer(transactOpts, contractBackend, minApply) trc21IssuerAddr, trc21Issuer, err := DeployTRC21Issuer(transactOpts, contractBackend, minApply)