* feat!(precompile): Add registry and genesis tests Based on evgeniy-scherbina's work, this adds a new precompile module which defines a contract moudule with an example noop contract that will be will be used for implementing test functions. In addition, it defines a registry module that instantiates stateful precompile contracts and associates them with an address in a global registry defined in kava-labs/go-ethereum. See precompile/README.md for more information. The kava-labs/go-ethereum and kava-labs/etheremint replace statements are updated to support these changes as well as an update to kvtool which includes genesis state for the registry.NoopContractAddress and initializes the contract's EthAccount with a non-zero sequence and codehash set to keccak256(0x01), and sets the contract code to 0x01. See tests/e2e/e2e_precompile_genesis_test.go for an overview of the expected genesis state for an enabled precompile. Co-authored-by: evgeniy-scherbina <evgeniy.shcherbina.es@gmail.com> * chore: Precompile readme improvements This fixes a typo (import -> important) and uses package terminology instead of unclear module terminology. This aligns best with golang terminology were modules and packages are distinctly different and modules are defined using go.mod. * chore: Improve noop contract godoc Add a more meaningful godoc where the noop contract is constructed. * chore(e2e): Improve comments around query checks Improve the clarity of comments around where the error is checked for accounts and why it is not checked directly. In addition, improve comment on why both grpc and rpc code is fetched and where they are used. --------- Co-authored-by: evgeniy-scherbina <evgeniy.shcherbina.es@gmail.com>
2.0 KiB
Precompile
The precompile
package defines stateful precompile contracts used for creating precompile contracts that enhance the EVM, enable interactions between cosmos state and EVM state, or are used soley for testing purposes.
This package is made of two subpackages:
contracts
- Defines stateful precompiles and their constructors.registry
- Defines stateful precompile addresses and registers them with the global registry defined atgithub.com/kava-labs/go-ethereum/precompile/modules
.
This is architected to isolate the dependency on the global registry (github.com/kava-labs/go-ethereum/precompile/modules
package) to as few places as possible, have one source of truth for address registration (see ./registry/registry.go
), and isolate registration testing to one package.
In order to use the precompile registry, it must be imported for it's init function to run and register the precompiles. For the kava app, this is done in the app.go
file with the import _ "github.com/kava-labs/kava/precompile/registry"
. This is done in the app.go
since this is the main file used for app dependencies and so all modules using the app cause the registry to be loaded. This is important for any consumers of the app outside of the kava cmd, as well as test code using the app for integration and unit testing.
Defining a new precompile
- Add the expected 0x address to the expected list in
./registry/registry_test.go
. - Create a new sub-directory under
./contracts
with acontract_test.go
andcontract.go
file. - Implement
NewContract
function with associated tests in contract and contract test files. - Add the contract registration to
./registry/registry.go
.
Contracts
Noop
This contract is used for testing purposes only and should not be used on public chains. The functions of this contract (once implemented), will be used to exercise and test the various aspects of the EVM such as gas usage, argument parsing, events, etc. The specific operations tested under this contract are still to be determined.