Skip to content

Commit

Permalink
London test fixes (#111)
Browse files Browse the repository at this point in the history
* Tests fixes

* SelfDestruct fix

* Rebase fix

* Journaling fix

* Tests fix

* e2e fix

* subGasLimit fix

* Fix

* Skip CheckEIP1559 e2e test

* Remove auxState field from Transition and use NewTransition function

* increase timeout for UT

* Suppress linting warnings

* underflow test fix

* Revert make file

* Remove panic

* Use %d in the error formatting

---------

Co-authored-by: Stefan Negovanović <[email protected]>
  • Loading branch information
goran-ethernal and Stefan-Ethernal authored Feb 19, 2024
1 parent d24f06f commit 28b8ddb
Show file tree
Hide file tree
Showing 20 changed files with 376 additions and 191 deletions.
2 changes: 0 additions & 2 deletions consensus/polybft/blockchain_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/0xPolygon/polygon-edge/consensus"
"github.com/0xPolygon/polygon-edge/contracts"
"github.com/0xPolygon/polygon-edge/state"
"github.com/0xPolygon/polygon-edge/state/runtime"
"github.com/0xPolygon/polygon-edge/types"
"github.com/umbracle/ethgo"
"github.com/umbracle/ethgo/contract"
Expand Down Expand Up @@ -219,7 +218,6 @@ func (s *stateProvider) Call(addr ethgo.Address, input []byte, opts *contract.Ca
input,
big.NewInt(0),
10000000,
runtime.NewAccessList(),
)
if result.Failed() {
return nil, result.Err
Expand Down
3 changes: 1 addition & 2 deletions consensus/polybft/contracts_initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/0xPolygon/polygon-edge/contracts"
"github.com/0xPolygon/polygon-edge/helper/hex"
"github.com/0xPolygon/polygon-edge/state"
"github.com/0xPolygon/polygon-edge/state/runtime"
"github.com/0xPolygon/polygon-edge/types"
"github.com/umbracle/ethgo/abi"
)
Expand Down Expand Up @@ -413,7 +412,7 @@ func approveEpochManagerAsSpender(polyBFTConfig PolyBFTConfig, transition *state

// callContract calls given smart contract function, encoded in input parameter
func callContract(from, to types.Address, input []byte, contractName string, transition *state.Transition) error {
result := transition.Call2(from, to, input, big.NewInt(0), contractCallGasLimit, runtime.NewAccessList())
result := transition.Call2(from, to, input, big.NewInt(0), contractCallGasLimit)
if result.Failed() {
if result.Reverted() {
if revertReason, err := abi.UnpackRevertError(result.ReturnValue); err == nil {
Expand Down
21 changes: 10 additions & 11 deletions consensus/polybft/sc_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/0xPolygon/polygon-edge/helper/common"
"github.com/0xPolygon/polygon-edge/helper/hex"
"github.com/0xPolygon/polygon-edge/state"
"github.com/0xPolygon/polygon-edge/state/runtime"
"github.com/0xPolygon/polygon-edge/types"
)

Expand Down Expand Up @@ -58,7 +57,7 @@ func TestIntegration_PerformExit(t *testing.T) {
input, err := abi.GetMethod(function).Encode(args)
require.NoError(t, err)

result := transition.Call2(deployerAddress, addr, input, big.NewInt(0), gasLimit, runtime.NewAccessList())
result := transition.Call2(deployerAddress, addr, input, big.NewInt(0), gasLimit)
require.True(t, result.Succeeded())

return result.ReturnValue
Expand Down Expand Up @@ -119,7 +118,7 @@ func TestIntegration_PerformExit(t *testing.T) {
}).EncodeAbi()
require.NoError(t, err)

result := transition.Call2(deployerAddress, rootERC20Addr, mintInput, nil, gasLimit, runtime.NewAccessList())
result := transition.Call2(deployerAddress, rootERC20Addr, mintInput, nil, gasLimit)
require.NoError(t, result.Err)

// approve
Expand All @@ -129,7 +128,7 @@ func TestIntegration_PerformExit(t *testing.T) {
}).EncodeAbi()
require.NoError(t, err)

result = transition.Call2(senderAddress, rootERC20Addr, approveInput, big.NewInt(0), gasLimit, runtime.NewAccessList())
result = transition.Call2(senderAddress, rootERC20Addr, approveInput, big.NewInt(0), gasLimit)
require.NoError(t, result.Err)

// deposit
Expand All @@ -141,7 +140,7 @@ func TestIntegration_PerformExit(t *testing.T) {
require.NoError(t, err)

// send sync events to childchain so that receiver can obtain tokens
result = transition.Call2(senderAddress, rootERC20PredicateAddr, depositInput, big.NewInt(0), gasLimit, runtime.NewAccessList())
result = transition.Call2(senderAddress, rootERC20PredicateAddr, depositInput, big.NewInt(0), gasLimit)
require.NoError(t, result.Err)

// simulate withdrawal from childchain to rootchain
Expand Down Expand Up @@ -231,7 +230,7 @@ func TestIntegration_PerformExit(t *testing.T) {
submitCheckpointEncoded, err := cm.abiEncodeCheckpointBlock(blockNumber, blockHash, extra, accSet)
require.NoError(t, err)

result = transition.Call2(senderAddress, checkpointManagerAddr, submitCheckpointEncoded, big.NewInt(0), gasLimit, runtime.NewAccessList())
result = transition.Call2(senderAddress, checkpointManagerAddr, submitCheckpointEncoded, big.NewInt(0), gasLimit)
require.NoError(t, result.Err)
require.Equal(t, getField(checkpointManagerAddr, contractsapi.CheckpointManager.Abi, "currentCheckpointBlockNumber")[31], uint8(1))

Expand All @@ -256,7 +255,7 @@ func TestIntegration_PerformExit(t *testing.T) {
}).EncodeAbi()
require.NoError(t, err)

result = transition.Call2(senderAddress, exitHelperContractAddress, exitFnInput, big.NewInt(0), gasLimit, runtime.NewAccessList())
result = transition.Call2(senderAddress, exitHelperContractAddress, exitFnInput, big.NewInt(0), gasLimit)
require.NoError(t, result.Err)

// check that first exit event is processed
Expand Down Expand Up @@ -383,7 +382,7 @@ func TestIntegration_CommitEpoch(t *testing.T) {
require.NoError(t, err)

// call commit epoch
result := transition.Call2(contracts.SystemCaller, contracts.EpochManagerContract, input, big.NewInt(0), 10000000000, runtime.NewAccessList())
result := transition.Call2(contracts.SystemCaller, contracts.EpochManagerContract, input, big.NewInt(0), 10000000000)
require.NoError(t, result.Err)
t.Logf("Number of validators %d on commit epoch, Gas used %+v\n", accSet.Len(), result.GasUsed)

Expand All @@ -392,7 +391,7 @@ func TestIntegration_CommitEpoch(t *testing.T) {
require.NoError(t, err)

// call commit epoch
result = transition.Call2(contracts.SystemCaller, contracts.EpochManagerContract, input, big.NewInt(0), 10000000000, runtime.NewAccessList())
result = transition.Call2(contracts.SystemCaller, contracts.EpochManagerContract, input, big.NewInt(0), 10000000000)
require.NoError(t, result.Err)
t.Logf("Number of validators %d on commit epoch, Gas used %+v\n", accSet.Len(), result.GasUsed)
}
Expand All @@ -402,14 +401,14 @@ func deployAndInitContract(t *testing.T, transition *state.Transition, bytecode
initCallback func() ([]byte, error)) types.Address {
t.Helper()

deployResult := transition.Create2(sender, bytecode, big.NewInt(0), 1e9, runtime.NewAccessList())
deployResult := transition.Create2(sender, bytecode, big.NewInt(0), 1e9)
assert.NoError(t, deployResult.Err)

if initCallback != nil {
initInput, err := initCallback()
require.NoError(t, err)

result := transition.Call2(sender, deployResult.Address, initInput, big.NewInt(0), 1e9, runtime.NewAccessList())
result := transition.Call2(sender, deployResult.Address, initInput, big.NewInt(0), 1e9)
require.NoError(t, result.Err)
}

Expand Down
5 changes: 2 additions & 3 deletions consensus/polybft/system_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/0xPolygon/polygon-edge/contracts"
"github.com/0xPolygon/polygon-edge/state"
itrie "github.com/0xPolygon/polygon-edge/state/immutable-trie"
"github.com/0xPolygon/polygon-edge/state/runtime"
"github.com/0xPolygon/polygon-edge/types"
"github.com/hashicorp/go-hclog"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -46,7 +45,7 @@ func TestSystemState_GetNextCommittedIndex(t *testing.T) {
transition := newTestTransition(t, nil)

// deploy a contract
result := transition.Create2(types.Address{}, bin, big.NewInt(0), 1000000000, runtime.NewAccessList())
result := transition.Create2(types.Address{}, bin, big.NewInt(0), 1000000000)
assert.NoError(t, result.Err)

provider := &stateProvider{
Expand Down Expand Up @@ -93,7 +92,7 @@ func TestSystemState_GetEpoch(t *testing.T) {
transition := newTestTransition(t, nil)

// deploy a contract
result := transition.Create2(types.Address{}, bin, big.NewInt(0), 1000000000, runtime.NewAccessList())
result := transition.Create2(types.Address{}, bin, big.NewInt(0), 1000000000)
assert.NoError(t, result.Err)

provider := &stateProvider{
Expand Down
2 changes: 2 additions & 0 deletions e2e-polybft/e2e/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,8 @@ func TestE2E_Consensus_CustomRewardToken(t *testing.T) {
// and check if balance of sender, receiver, burn contract and miner is updates correctly
// in accordance with EIP-1559 specifications
func TestE2E_Consensus_EIP1559Check(t *testing.T) {
t.Skip("TODO - since we removed burn from evm, this should be fixed after the burn solution")

sender, err := wallet.GenerateKey()
require.NoError(t, err)

Expand Down
4 changes: 2 additions & 2 deletions helper/predeployment/predeployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"math"
"math/big"

"github.com/hashicorp/go-hclog"
"github.com/umbracle/ethgo/abi"

"github.com/0xPolygon/polygon-edge/chain"
Expand Down Expand Up @@ -61,14 +62,13 @@ func getPredeployAccount(address types.Address, input []byte,
big.NewInt(0),
math.MaxInt64,
input,
runtime.NewAccessList(),
)

// Enable all forks
config := chain.AllForksEnabled.At(0)

// Create a transition
transition := state.NewTransition(config, snapshot, radix)
transition := state.NewTransition(hclog.NewNullLogger(), config, snapshot, radix)
transition.ContextPtr().ChainID = chainID

// Run the transition through the EVM
Expand Down
Loading

0 comments on commit 28b8ddb

Please sign in to comment.