github.com/MetalBlockchain/subnet-evm@v0.4.9/plugin/evm/static_service_test.go (about) 1 // Copyright (C) 2019-2021, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package evm 5 6 import ( 7 "encoding/json" 8 "math/big" 9 "testing" 10 11 "github.com/MetalBlockchain/metalgo/utils/formatting" 12 "github.com/MetalBlockchain/subnet-evm/core" 13 "github.com/MetalBlockchain/subnet-evm/params" 14 "github.com/stretchr/testify/assert" 15 ) 16 17 var testGenesisJSON = "{\"config\":{\"chainId\":43111,\"homesteadBlock\":0,\"eip150Block\":0,\"eip150Hash\":\"0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0\",\"eip155Block\":0,\"eip158Block\":0,\"byzantiumBlock\":0,\"constantinopleBlock\":0,\"petersburgBlock\":0,\"istanbulBlock\":0,\"muirGlacierBlock\":0,\"subnetEVMTimestamp\":0},\"nonce\":\"0x0\",\"timestamp\":\"0x0\",\"extraData\":\"0x00\",\"gasLimit\":\"0x5f5e100\",\"difficulty\":\"0x0\",\"mixHash\":\"0x0000000000000000000000000000000000000000000000000000000000000000\",\"coinbase\":\"0x0000000000000000000000000000000000000000\",\"alloc\":{\"0100000000000000000000000000000000000000\":{\"code\":\"0x7300000000000000000000000000000000000000003014608060405260043610603d5760003560e01c80631e010439146042578063b6510bb314606e575b600080fd5b605c60048036036020811015605657600080fd5b503560b1565b60408051918252519081900360200190f35b818015607957600080fd5b5060af60048036036080811015608e57600080fd5b506001600160a01b03813516906020810135906040810135906060013560b6565b005b30cd90565b836001600160a01b031681836108fc8690811502906040516000604051808303818888878c8acf9550505050505015801560f4573d6000803e3d6000fd5b505050505056fea26469706673582212201eebce970fe3f5cb96bf8ac6ba5f5c133fc2908ae3dcd51082cfee8f583429d064736f6c634300060a0033\",\"balance\":\"0x0\"}},\"number\":\"0x0\",\"gasUsed\":\"0x0\",\"parentHash\":\"0x0000000000000000000000000000000000000000000000000000000000000000\"}" 18 19 func TestBuildGenesis(t *testing.T) { 20 ss := CreateStaticService() 21 22 genesis := &core.Genesis{} 23 if err := json.Unmarshal([]byte(testGenesisJSON), genesis); err != nil { 24 t.Fatalf("Problem unmarshaling genesis JSON: %s", err) 25 } 26 27 // add test allocs 28 testAlloc := core.GenesisAlloc{ 29 testEthAddrs[0]: core.GenesisAccount{Balance: genesisBalance}, 30 testEthAddrs[1]: core.GenesisAccount{Balance: genesisBalance}, 31 } 32 genesis.Alloc = testAlloc 33 genesis.Config.FeeConfig = params.DefaultFeeConfig 34 testGasLimit := big.NewInt(999999) 35 genesis.Config.FeeConfig.GasLimit = testGasLimit 36 genesis.GasLimit = testGasLimit.Uint64() 37 38 args := &BuildGenesisArgs{GenesisData: genesis} 39 reply := &BuildGenesisReply{} 40 err := ss.BuildGenesis(nil, args, reply) 41 if err != nil { 42 t.Fatalf("Failed to create test genesis") 43 } 44 // now decode 45 genesisBytes, err := formatting.Decode(reply.Encoding, reply.GenesisBytes) 46 if err != nil { 47 t.Fatalf("Failed to decode genesis bytes: %s", err) 48 } 49 // unmarshal it again 50 decodedGenesis := &core.Genesis{} 51 decodedGenesis.UnmarshalJSON(genesisBytes) 52 // test 53 assert.Equal(t, testGasLimit, decodedGenesis.Config.FeeConfig.GasLimit) 54 assert.Equal(t, testAlloc, decodedGenesis.Alloc) 55 } 56 57 func TestDecodeGenesis(t *testing.T) { 58 ss := CreateStaticService() 59 60 genesis := &core.Genesis{} 61 if err := json.Unmarshal([]byte(testGenesisJSON), genesis); err != nil { 62 t.Fatalf("Problem unmarshaling genesis JSON: %s", err) 63 } 64 65 // add test allocs 66 testAlloc := core.GenesisAlloc{ 67 testEthAddrs[0]: core.GenesisAccount{Balance: genesisBalance}, 68 testEthAddrs[1]: core.GenesisAccount{Balance: genesisBalance}, 69 } 70 genesis.Alloc = testAlloc 71 genesis.Config.FeeConfig = params.DefaultFeeConfig 72 testGasLimit := big.NewInt(999999) 73 genesis.Config.FeeConfig.GasLimit = testGasLimit 74 genesis.GasLimit = testGasLimit.Uint64() 75 76 args := &BuildGenesisArgs{GenesisData: genesis} 77 reply := &BuildGenesisReply{} 78 err := ss.BuildGenesis(nil, args, reply) 79 if err != nil { 80 t.Fatalf("Failed to create test genesis") 81 } 82 83 // now decode 84 decArgs := &DecodeGenesisArgs{GenesisBytes: reply.GenesisBytes} 85 decReply := &DecodeGenesisReply{} 86 err = ss.DecodeGenesis(nil, decArgs, decReply) 87 if err != nil { 88 t.Fatalf("Failed to create test genesis") 89 } 90 decodedGenesis := decReply.Genesis 91 92 // test 93 assert.Equal(t, testGasLimit, decodedGenesis.Config.FeeConfig.GasLimit) 94 assert.Equal(t, testAlloc, decodedGenesis.Alloc) 95 }