-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
include tests for precompiles package
- Loading branch information
Showing
6 changed files
with
484 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package precompiles_test | ||
|
||
import ( | ||
"testing" | ||
|
||
storetypes "github.com/cosmos/cosmos-sdk/store/types" | ||
ethparams "github.com/ethereum/go-ethereum/params" | ||
"github.com/stretchr/testify/require" | ||
ethermint "github.com/zeta-chain/ethermint/types" | ||
"github.com/zeta-chain/zetacore/precompiles" | ||
"github.com/zeta-chain/zetacore/testutil/keeper" | ||
) | ||
|
||
func Test_StatefulContracts(t *testing.T) { | ||
k, ctx, _, _ := keeper.FungibleKeeper(t) | ||
gasConfig := storetypes.TransientGasConfig() | ||
|
||
var encoding ethermint.EncodingConfig | ||
appCodec := encoding.Codec | ||
|
||
var expectedContracts int | ||
for _, enabled := range precompiles.EnabledStatefulContracts { | ||
if enabled { | ||
expectedContracts++ | ||
} | ||
} | ||
|
||
// StatefulContracts() should return all the enabled contracts. | ||
contracts := precompiles.StatefulContracts(k, appCodec, gasConfig) | ||
require.NotNil(t, contracts, "StatefulContracts() should not return a nil slice") | ||
require.Len(t, contracts, expectedContracts, "StatefulContracts() should return all the enabled contracts") | ||
|
||
// Extract the contract function from the first contract. | ||
customContractFn := contracts[0] | ||
contract := customContractFn(ctx, ethparams.Rules{}) | ||
|
||
// Check the contract function returns a valid address. | ||
contractAddr := contract.Address() | ||
require.NotNil(t, contractAddr, "The called contract should have a valid address") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
[ | ||
{ | ||
"inputs": [], | ||
"name": "testBech32ToHexAddr", | ||
"outputs": [ | ||
{ | ||
"internalType": "bool", | ||
"name": "", | ||
"type": "bool" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "testBech32ify", | ||
"outputs": [ | ||
{ | ||
"internalType": "bool", | ||
"name": "", | ||
"type": "bool" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "string", | ||
"name": "method", | ||
"type": "string" | ||
}, | ||
{ | ||
"internalType": "address", | ||
"name": "addr", | ||
"type": "address" | ||
} | ||
], | ||
"name": "testRegularCall", | ||
"outputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "", | ||
"type": "uint256" | ||
} | ||
], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
608060405234801561001057600080fd5b50610918806100206000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c806342875b1d1461004657806348fc7db114610064578063d7c9bd0214610094575b600080fd5b61004e6100b2565b60405161005b9190610675565b60405180910390f35b61007e6004803603810190610079919061053e565b6101ae565b60405161008b91906106e2565b60405180910390f35b61009c61024b565b6040516100a99190610675565b60405180910390f35b6000806040518060600160405280602b81526020016108b8602b91399050600073b9dbc229bf588a613c00bee8e662727ab8121cfe90506000606573ffffffffffffffffffffffffffffffffffffffff1663e4e2a4ec846040518263ffffffff1660e01b81526004016101259190610690565b60206040518083038186803b15801561013d57600080fd5b505afa158015610151573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061017591906104c8565b90508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614935050505090565b600080606573ffffffffffffffffffffffffffffffffffffffff166393e3663d85856040518363ffffffff1660e01b81526004016101ed9291906106b2565b602060405180830381600087803b15801561020757600080fd5b505af115801561021b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061023f919061059a565b90508091505092915050565b6000806040518060400160405280600481526020017f7a657461000000000000000000000000000000000000000000000000000000008152509050600073b9dbc229bf588a613c00bee8e662727ab8121cfe905060006040518060600160405280602b81526020016108b8602b913990506000606573ffffffffffffffffffffffffffffffffffffffff16630615b74e85856040518363ffffffff1660e01b81526004016102fa9291906106b2565b60006040518083038186803b15801561031257600080fd5b505afa158015610326573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f8201168201806040525081019061034f91906104f5565b905081604051602001610362919061065e565b6040516020818303038152906040528051906020012081604051602001610389919061065e565b604051602081830303815290604052805190602001201494505050505090565b60006103bc6103b784610722565b6106fd565b9050828152602081018484840111156103d8576103d7610869565b5b6103e38482856107c2565b509392505050565b60006103fe6103f984610722565b6106fd565b90508281526020810184848401111561041a57610419610869565b5b6104258482856107d1565b509392505050565b60008135905061043c81610889565b92915050565b60008151905061045181610889565b92915050565b600082601f83011261046c5761046b610864565b5b813561047c8482602086016103a9565b91505092915050565b600082601f83011261049a57610499610864565b5b81516104aa8482602086016103eb565b91505092915050565b6000815190506104c2816108a0565b92915050565b6000602082840312156104de576104dd610873565b5b60006104ec84828501610442565b91505092915050565b60006020828403121561050b5761050a610873565b5b600082015167ffffffffffffffff8111156105295761052861086e565b5b61053584828501610485565b91505092915050565b6000806040838503121561055557610554610873565b5b600083013567ffffffffffffffff8111156105735761057261086e565b5b61057f85828601610457565b92505060206105908582860161042d565b9150509250929050565b6000602082840312156105b0576105af610873565b5b60006105be848285016104b3565b91505092915050565b6105d08161077a565b82525050565b6105df8161078c565b82525050565b60006105f082610753565b6105fa818561075e565b935061060a8185602086016107d1565b61061381610878565b840191505092915050565b600061062982610753565b610633818561076f565b93506106438185602086016107d1565b80840191505092915050565b610658816107b8565b82525050565b600061066a828461061e565b915081905092915050565b600060208201905061068a60008301846105d6565b92915050565b600060208201905081810360008301526106aa81846105e5565b905092915050565b600060408201905081810360008301526106cc81856105e5565b90506106db60208301846105c7565b9392505050565b60006020820190506106f7600083018461064f565b92915050565b6000610707610718565b90506107138282610804565b919050565b6000604051905090565b600067ffffffffffffffff82111561073d5761073c610835565b5b61074682610878565b9050602081019050919050565b600081519050919050565b600082825260208201905092915050565b600081905092915050565b600061078582610798565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b82818337600083830152505050565b60005b838110156107ef5780820151818401526020810190506107d4565b838111156107fe576000848401525b50505050565b61080d82610878565b810181811067ffffffffffffffff8211171561082c5761082b610835565b5b80604052505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b6108928161077a565b811461089d57600080fd5b50565b6108a9816107b8565b81146108b457600080fd5b5056fe7a65746131683864757932646c747a39787a307171686d357776636e6a303275707938383766796e343375a26469706673582212205d1317177480909fff852a3871dc5d7fbdcb2fec3c47b91fc472fa775517c70264736f6c63430008070033 |
Oops, something went wrong.