private static BlockchainTest Convert(string name, BlockchainTestJson testJson)
        {
            if (testJson.LoadFailure != null)
            {
                return(new BlockchainTest
                {
                    Name = name,
                    LoadFailure = testJson.LoadFailure
                });
            }

            BlockchainTest test = new BlockchainTest();

            test.Name    = name;
            test.Network = testJson.EthereumNetwork;
            test.NetworkAfterTransition = testJson.EthereumNetworkAfterTransition;
            test.TransitionBlockNumber  = (UInt256)testJson.TransitionBlockNumber;
            test.LastBlockHash          = new Keccak(testJson.LastBlockHash);
            test.GenesisRlp             = testJson.GenesisRlp == null ? null : new Rlp(Bytes.FromHexString(testJson.GenesisRlp));
            test.GenesisBlockHeader     = testJson.GenesisBlockHeader;
            test.Blocks    = testJson.Blocks;
            test.PostState = testJson.PostState.ToDictionary(p => new Address(p.Key), p => Convert(p.Value));
            test.Pre       = testJson.Pre.ToDictionary(p => new Address(p.Key), p => Convert(p.Value));
            return(test);
        }
示例#2
0
        private static BlockchainTest Convert(string name, BlockchainTestJson testJson)
        {
            BlockchainTest test = new BlockchainTest();

            test.Name    = name;
            test.Network = testJson.EthereumNetwork;
            test.NetworkAfterTransition = testJson.EthereumNetworkAfterTransition;
            test.TransitionBlockNumber  = testJson.TransitionBlockNumber;
            test.LastBlockHash          = new Keccak(new Hex(testJson.LastBlockHash));
            test.GenesisRlp             = testJson.GenesisRlp == null ? null : new Rlp(Hex.ToBytes(testJson.GenesisRlp));
            test.GenesisBlockHeader     = testJson.GenesisBlockHeader;
            test.Blocks    = testJson.Blocks;
            test.PostState = testJson.PostState.ToDictionary(p => new Address(p.Key), p => Convert(p.Value));
            test.Pre       = testJson.Pre.ToDictionary(p => new Address(p.Key), p => Convert(p.Value));
            return(test);
        }
        public static IEnumerable <BlockchainTest> Convert(string name, BlockchainTestJson testJson)
        {
            if (testJson.LoadFailure != null)
            {
                return(Enumerable.Repeat(new BlockchainTest
                {
                    Name = name,
                    LoadFailure = testJson.LoadFailure
                }, 1));
            }

            List <BlockchainTest> blockchainTests = new List <BlockchainTest>();

            foreach (var postStateBySpec in testJson.Post)
            {
                foreach (PostStateJson stateJson in postStateBySpec.Value)
                {
                    BlockchainTest test = new BlockchainTest();
                    test.Name              = name + $"_d{stateJson.Indexes.Data}g{stateJson.Indexes.Gas}v{stateJson.Indexes.Value}";
                    test.ForkName          = postStateBySpec.Key;
                    test.Fork              = ParseSpec(postStateBySpec.Key);
                    test.PreviousHash      = testJson.Env.PreviousHash;
                    test.CurrentCoinbase   = testJson.Env.CurrentCoinbase;
                    test.CurrentDifficulty = testJson.Env.CurrentDifficulty;
                    test.CurrentGasLimit   = testJson.Env.CurrentGasLimit;
                    test.CurrentNumber     = testJson.Env.CurrentNumber;
                    test.CurrentTimestamp  = testJson.Env.CurrentTimestamp;
                    test.PostReceiptsRoot  = stateJson.Logs;
                    test.PostHash          = stateJson.Hash;
                    test.Pre         = testJson.Pre.ToDictionary(p => new Address(p.Key), p => Convert(p.Value));
                    test.Transaction = Convert(stateJson, testJson.Transaction);
                    blockchainTests.Add(test);
                }
            }

            return(blockchainTests);
        }