Skip to content

Commit

Permalink
add first e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
fbac committed Aug 15, 2024
1 parent e58c783 commit 58b865a
Show file tree
Hide file tree
Showing 12 changed files with 501 additions and 9 deletions.
5 changes: 1 addition & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,9 +556,6 @@ func New(
)
evmSs := app.GetSubspace(evmtypes.ModuleName)

// Get gas config for stateful contracts.
gasConfig := storetypes.TransientGasConfig()

app.EvmKeeper = evmkeeper.NewKeeper(
appCodec,
keys[evmtypes.StoreKey],
Expand All @@ -573,7 +570,7 @@ func New(
precompiles.StatefulContracts(
app.FungibleKeeper,
appCodec,
gasConfig,
storetypes.TransientGasConfig(),
),
app.ConsensusParamsKeeper,
aggregateAllKeys(keys, tKeys, memKeys),
Expand Down
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* [2634](https://github.com/zeta-chain/node/pull/2634) - add support for EIP-1559 gas fees
* [2597](https://github.com/zeta-chain/node/pull/2597) - Add generic rpc metrics to zetaclient
* [2538](https://github.com/zeta-chain/node/pull/2538) - add background worker routines to shutdown zetaclientd when needed for tss migration
* [2633](https://github.com/zeta-chain/node/pull/2633) - support for stateful precompiled contracts.

### Refactor

Expand Down Expand Up @@ -57,7 +58,6 @@
* [2524](https://github.com/zeta-chain/node/pull/2524) - add inscription envelop parsing
* [2560](https://github.com/zeta-chain/node/pull/2560) - add support for Solana SOL token withdraw
* [2533](https://github.com/zeta-chain/node/pull/2533) - parse memo from both OP_RETURN and inscription
* [2633](https://github.com/zeta-chain/node/pull/2633) - support for stateful precompiled contracts.

### Refactor

Expand Down Expand Up @@ -115,6 +115,7 @@
* [2415](https://github.com/zeta-chain/node/pull/2415) - add e2e test for upgrade and test admin functionalities
* [2440](https://github.com/zeta-chain/node/pull/2440) - Add e2e test for TSS migration
* [2473](https://github.com/zeta-chain/node/pull/2473) - add e2e tests for most used admin transactions
* [2703](https://github.com/zeta-chain/node/pull/2703) - add e2e tests for stateful precompiled contracts

### Fixes

Expand Down
1 change: 1 addition & 0 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
e2etests.TestERC20DepositRestrictedName,
}
zetaTests := []string{
e2etests.TestZetaPrecompilesName,
e2etests.TestZetaWithdrawName,
e2etests.TestMessagePassingExternalChainsName,
e2etests.TestMessagePassingRevertFailExternalChainsName,
Expand Down
7 changes: 7 additions & 0 deletions e2e/e2etests/e2etests.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const (
TestZetaDepositRestrictedName = "zeta_deposit_restricted"
TestZetaWithdrawName = "zeta_withdraw"
TestZetaWithdrawBTCRevertName = "zeta_withdraw_btc_revert" // #nosec G101 - not a hardcoded password
TestZetaPrecompilesName = "zeta_precompiles"

/*
Message passing tests
Expand Down Expand Up @@ -123,6 +124,12 @@ var AllE2ETests = []runner.E2ETest{
/*
ZETA tests
*/
runner.NewE2ETest(
TestZetaPrecompilesName,
"call Regular stateful precompiled contract",
[]runner.ArgDefinition{},
TestPrecompilesRegular,
),
runner.NewE2ETest(
TestZetaDepositName,
"deposit ZETA from Ethereum to ZEVM",
Expand Down
27 changes: 27 additions & 0 deletions e2e/e2etests/test_precompiles_regular.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package e2etests

import (
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"

"github.com/zeta-chain/zetacore/e2e/runner"
"github.com/zeta-chain/zetacore/precompiles/regular"
)

func TestPrecompilesRegular(r *runner.E2ERunner, args []string) {
require.Len(r, args, 0, "No arguments expected")

dummyBech32Addr := "1h8duy2dltz9xz0qqhm5wvcnj02upy887fyn43u"

// Call the Regular contract in the static precompile address.
contract, err := regular.NewRegularCaller(regular.ContractAddress, r.EVMClient)
require.NoError(r, err, "Failed to create Regular contract caller")

addr, err := contract.Bech32ToHexAddr(
nil,
common.HexToAddress("0xB9Dbc229Bf588A613C00BEE8e662727AB8121cfE").String(),
)
require.NoError(r, err, "Failed to call Bech32ToHexAddr in Regular precompiled contract")

require.Equal(r, dummyBech32Addr, addr.String(), "Expected address %s, got %s", dummyBech32Addr, addr.String())
}
File renamed without changes.
264 changes: 264 additions & 0 deletions precompiles/regular/IRegularABI.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
9 changes: 5 additions & 4 deletions precompiles/regular/regular.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,15 @@ func (rc *Contract) Abi() abi.ABI {
func (rc *Contract) RequiredGas(input []byte) uint64 {

Check warning on line 98 in precompiles/regular/regular.go

View check run for this annotation

Codecov / codecov/patch

precompiles/regular/regular.go#L98

Added line #L98 was not covered by tests
// base cost to prevent large input size
baseCost := uint64(len(input)) * rc.kvGasConfig.WriteCostPerByte

Check warning on line 100 in precompiles/regular/regular.go

View check run for this annotation

Codecov / codecov/patch

precompiles/regular/regular.go#L100

Added line #L100 was not covered by tests

// get methodID (first 4 bytes)
var methodID [4]byte
copy(methodID[:], input[:4])

Check warning on line 104 in precompiles/regular/regular.go

View check run for this annotation

Codecov / codecov/patch

precompiles/regular/regular.go#L103-L104

Added lines #L103 - L104 were not covered by tests
requiredGas, ok := GasRequiredByMethod[methodID]
if ok {

if requiredGas, ok := GasRequiredByMethod[methodID]; ok {
return requiredGas + baseCost

Check warning on line 107 in precompiles/regular/regular.go

View check run for this annotation

Codecov / codecov/patch

precompiles/regular/regular.go#L106-L107

Added lines #L106 - L107 were not covered by tests
}

return baseCost

Check warning on line 110 in precompiles/regular/regular.go

View check run for this annotation

Codecov / codecov/patch

precompiles/regular/regular.go#L110

Added line #L110 was not covered by tests
}

Expand Down Expand Up @@ -239,8 +242,6 @@ func (rc *Contract) Run(evm *vm.EVM, contract *vm.Contract, _ bool) ([]byte, err
return rc.Bech32ToHexAddr(method, args)
case Bech32ifyMethodName:
return rc.Bech32ify(method, args)
// case OtherMethods:
// ..
default:
return nil, errors.New("unknown method")

Check warning on line 246 in precompiles/regular/regular.go

View check run for this annotation

Codecov / codecov/patch

precompiles/regular/regular.go#L241-L246

Added lines #L241 - L246 were not covered by tests
}
Expand Down
Loading

0 comments on commit 58b865a

Please sign in to comment.