diff --git a/graft/coreth/Taskfile.yml b/graft/coreth/Taskfile.yml index 85750d74d078..f82f3c14714c 100644 --- a/graft/coreth/Taskfile.yml +++ b/graft/coreth/Taskfile.yml @@ -119,6 +119,7 @@ tasks: E2E_TARGET: ./graft/coreth/tests/warp cmds: - cmd: ./scripts/run_task.sh build + - cmd: cd graft/subnet-evm && ./scripts/build.sh - cmd: bash -x ./scripts/tests.e2e.sh {{.CLI_ARGS}} test-e2e-warp-ci: # consolidated test-e2e-warp @@ -129,4 +130,5 @@ tasks: E2E_SERIAL: 1 cmds: - cmd: ./scripts/run_task.sh build-race + - cmd: cd graft/subnet-evm && ./scripts/build.sh - cmd: bash -x ./scripts/tests.e2e.sh {{.CLI_ARGS}} diff --git a/graft/coreth/tests/utils/tmpnet.go b/graft/coreth/tests/utils/tmpnet.go index 2e830c60bf56..811f2a36718c 100644 --- a/graft/coreth/tests/utils/tmpnet.go +++ b/graft/coreth/tests/utils/tmpnet.go @@ -4,8 +4,12 @@ package utils import ( + "encoding/json" + "github.com/ava-labs/avalanchego/config" + "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/tests/fixture/tmpnet" + "github.com/ava-labs/avalanchego/utils/constants" ) var DefaultChainConfig = map[string]any{ @@ -14,7 +18,7 @@ var DefaultChainConfig = map[string]any{ "local-txs-enabled": true, } -func NewTmpnetNetwork(owner string, nodes []*tmpnet.Node, flags tmpnet.FlagsMap) *tmpnet.Network { +func NewTmpnetNetwork(owner string, nodes []*tmpnet.Node, flags tmpnet.FlagsMap, subnets ...*tmpnet.Subnet) *tmpnet.Network { defaultFlags := tmpnet.FlagsMap{} defaultFlags.SetDefaults(flags) defaultFlags.SetDefaults(tmpnet.FlagsMap{ @@ -24,5 +28,37 @@ func NewTmpnetNetwork(owner string, nodes []*tmpnet.Node, flags tmpnet.FlagsMap) Owner: owner, DefaultFlags: defaultFlags, Nodes: nodes, + Subnets: subnets, + } +} + +// Create the configuration that will enable creation and access to a +// subnet created on a temporary network. +func NewTmpnetSubnet(name string, genesis []byte, chainConfig map[string]any, nodes ...*tmpnet.Node) *tmpnet.Subnet { + if len(nodes) == 0 { + panic("a subnet must be validated by at least one node") + } + + validatorIDs := make([]ids.NodeID, len(nodes)) + for i, node := range nodes { + validatorIDs[i] = node.NodeID + } + + chainConfigBytes, err := json.Marshal(chainConfig) + if err != nil { + panic(err) + } + + return &tmpnet.Subnet{ + Name: name, + Chains: []*tmpnet.Chain{ + { + VMID: constants.SubnetEVMID, + Genesis: genesis, + Config: string(chainConfigBytes), + PreFundedKey: tmpnet.HardhatKey, + }, + }, + ValidatorIDs: validatorIDs, } } diff --git a/graft/coreth/tests/warp/genesis.json b/graft/coreth/tests/warp/genesis.json new file mode 100644 index 000000000000..e4c17d05f000 --- /dev/null +++ b/graft/coreth/tests/warp/genesis.json @@ -0,0 +1,45 @@ +{ + "config": { + "chainId": 99999, + "homesteadBlock": 0, + "eip150Block": 0, + "eip155Block": 0, + "eip158Block": 0, + "byzantiumBlock": 0, + "constantinopleBlock": 0, + "petersburgBlock": 0, + "istanbulBlock": 0, + "muirGlacierBlock": 0, + "feeConfig": { + "gasLimit": 20000000, + "minBaseFee": 1000000000, + "targetGas": 100000000, + "baseFeeChangeDenominator": 48, + "minBlockGasCost": 0, + "maxBlockGasCost": 10000000, + "targetBlockRate": 2, + "blockGasCostStep": 500000 + }, + "warpConfig": { + "blockTimestamp": 1607144400 + } + }, + "alloc": { + "8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC": { + "balance": "0x52B7D2DCC80CD2E4000000" + }, + "0x0Fa8EA536Be85F32724D57A37758761B86416123": { + "balance": "0x52B7D2DCC80CD2E4000000" + } + }, + "nonce": "0x0", + "timestamp": "0x5FCB13D0", + "extraData": "0x00", + "gasLimit": "0x1312D00", + "difficulty": "0x0", + "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "coinbase": "0x0000000000000000000000000000000000000000", + "number": "0x0", + "gasUsed": "0x0", + "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000" +} diff --git a/graft/coreth/tests/warp/warp_test.go b/graft/coreth/tests/warp/warp_test.go index 83c34cb26b51..e5ddfe143cac 100644 --- a/graft/coreth/tests/warp/warp_test.go +++ b/graft/coreth/tests/warp/warp_test.go @@ -18,6 +18,8 @@ import ( "github.com/ava-labs/libevm/crypto" "github.com/stretchr/testify/require" + _ "embed" + "github.com/ava-labs/avalanchego/api/info" "github.com/ava-labs/avalanchego/graft/coreth/accounts/abi/bind" "github.com/ava-labs/avalanchego/graft/coreth/cmd/simulator/key" @@ -43,10 +45,15 @@ import ( ginkgo "github.com/onsi/ginkgo/v2" ) +const subnetAName = "warp-subnet-a" + var ( + //go:embed genesis.json + genesis []byte + flagVars *e2e.FlagVars - cChainSubnetDetails *Subnet + subnetA, cChainSubnetDetails *Subnet testPayload = []byte{1, 2, 3} ) @@ -74,7 +81,6 @@ func TestE2E(t *testing.T) { var _ = ginkgo.SynchronizedBeforeSuite(func() []byte { // Run only once in the first ginkgo process - tc := e2e.NewTestContext() nodes := tmpnet.NewNodesOrPanic(tmpnet.DefaultNodeCount) @@ -85,6 +91,7 @@ var _ = ginkgo.SynchronizedBeforeSuite(func() []byte { "coreth-warp-e2e", nodes, tmpnet.FlagsMap{}, + utils.NewTmpnetSubnet(subnetAName, genesis, utils.DefaultChainConfig, nodes...), ), ) @@ -108,6 +115,15 @@ var _ = ginkgo.SynchronizedBeforeSuite(func() []byte { validatorURIs[i] = node.URI } + tmpnetSubnetA := network.GetSubnet(subnetAName) + require.NotNil(tmpnetSubnetA) + subnetA = &Subnet{ + SubnetID: tmpnetSubnetA.SubnetID, + BlockchainID: tmpnetSubnetA.Chains[0].ChainID, + PreFundedKey: tmpnetSubnetA.Chains[0].PreFundedKey.ToECDSA(), + ValidatorURIs: validatorURIs, + } + infoClient := info.NewClient(network.Nodes[0].URI) cChainBlockchainID, err := infoClient.GetBlockchainID(tc.DefaultContext(), "C") require.NoError(err) @@ -128,12 +144,8 @@ var _ = ginkgo.Describe("[Warp]", func() { } testCombinations := []testCombination{ - // TODO: Uncomment these tests when we have a way to run them in CI, currently we should not depend on Subnet-EVM - // as Coreth and Subnet-EVM have different release cycles. The problem is that once we update AvalancheGo (protocol version), - // we need to update Subnet-EVM to the same protocol version. Until then all Subnet-EVM tests are broken, so it's blocking Coreth development. - // It's best to not run these tests until we have a way to run them in CI. - // {"SubnetA -> C-Chain", func() *Subnet { return subnetA }, func() *Subnet { return cChainSubnetDetails }}, - // {"C-Chain -> SubnetA", func() *Subnet { return cChainSubnetDetails }, func() *Subnet { return subnetA }}, + {"SubnetA -> C-Chain", func() *Subnet { return subnetA }, func() *Subnet { return cChainSubnetDetails }}, + {"C-Chain -> SubnetA", func() *Subnet { return cChainSubnetDetails }, func() *Subnet { return subnetA }}, {"C-Chain -> C-Chain", func() *Subnet { return cChainSubnetDetails }, func() *Subnet { return cChainSubnetDetails }}, } diff --git a/graft/subnet-evm/tests/load/load_test.go b/graft/subnet-evm/tests/load/load_test.go index 332f73849f47..d25362b13ea5 100644 --- a/graft/subnet-evm/tests/load/load_test.go +++ b/graft/subnet-evm/tests/load/load_test.go @@ -56,7 +56,7 @@ var _ = ginkgo.Describe("[Load Simulator]", ginkgo.Ordered, func() { repoRoot, err = e2e.GetRepoRootPath("tests/load") require.NoError(err) - nodes := utils.NewTmpnetNodes(nodeCount) + nodes := tmpnet.NewNodesOrPanic(nodeCount) env = e2e.NewTestEnvironment( tc, flagVars, diff --git a/graft/subnet-evm/tests/utils/tmpnet.go b/graft/subnet-evm/tests/utils/tmpnet.go index e36189b3f4fd..01cf2d688ac2 100644 --- a/graft/subnet-evm/tests/utils/tmpnet.go +++ b/graft/subnet-evm/tests/utils/tmpnet.go @@ -18,16 +18,6 @@ var DefaultChainConfig = map[string]any{ "local-txs-enabled": true, } -func NewTmpnetNodes(count int) []*tmpnet.Node { - nodes := make([]*tmpnet.Node, count) - for i := range nodes { - node := tmpnet.NewNode() - _ = node.EnsureKeys() // guaranteed to be nil for new node - nodes[i] = node - } - return nodes -} - func NewTmpnetNetwork(owner string, nodes []*tmpnet.Node, flags tmpnet.FlagsMap, subnets ...*tmpnet.Subnet) *tmpnet.Network { defaultFlags := tmpnet.FlagsMap{} defaultFlags.SetDefaults(flags) diff --git a/graft/subnet-evm/tests/warp/warp_test.go b/graft/subnet-evm/tests/warp/warp_test.go index b77901b46941..55ba7ee01402 100644 --- a/graft/subnet-evm/tests/warp/warp_test.go +++ b/graft/subnet-evm/tests/warp/warp_test.go @@ -88,10 +88,9 @@ func TestE2E(t *testing.T) { var _ = ginkgo.SynchronizedBeforeSuite(func() []byte { // Run only once in the first ginkgo process - tc := e2e.NewTestContext() - nodes := utils.NewTmpnetNodes(tmpnet.DefaultNodeCount) + nodes := tmpnet.NewNodesOrPanic(tmpnet.DefaultNodeCount) env := e2e.NewTestEnvironment( tc, flagVars,