コード例 #1
0
        private void RunTest(TransactionTest test, IReleaseSpec spec)
        {
            //TestContext.CurrentContext.Test.Properties.Set("Category", test.Network); // no longer public

            ValidTransactionTest validTest = test as ValidTransactionTest;

            Nethermind.Core.Transaction transaction;
            try
            {
                Rlp rlp = new Rlp(Bytes.FromHexString(test.Rlp));
                transaction = Rlp.Decode <Nethermind.Core.Transaction>(rlp);
            }
            catch (Exception)
            {
                if (validTest == null)
                {
                    return;
                }

                throw;
            }

            bool useChainId = transaction.Signature.V > 28;

            SignatureValidator   signatureValidator = new SignatureValidator(useChainId ? ChainId.MainNet : 0);
            TransactionValidator validator          = new TransactionValidator(signatureValidator);

            if (validTest != null)
            {
                Assert.AreEqual(validTest.Value, transaction.Value, "value");
                Assert.AreEqual(validTest.Data, transaction.Data ?? transaction.Init, "data");
                Assert.AreEqual(validTest.GasLimit, transaction.GasLimit, "gasLimit");
                Assert.AreEqual(validTest.GasPrice, transaction.GasPrice, "gasPrice");
                Assert.AreEqual(validTest.Nonce, transaction.Nonce, "nonce");
                Assert.AreEqual(validTest.To, transaction.To, "to");
                Assert.True(validator.IsWellFormed(transaction, spec));

                Signature expectedSignature = new Signature(validTest.R, validTest.S, validTest.V);
                Assert.AreEqual(expectedSignature, transaction.Signature, "signature");
//                if(useChainId && spec.IsEip155Enabled)
//
                IEthereumEcdsa ecdsa    = new EthereumEcdsa(new SingleReleaseSpecProvider(spec, useChainId ? (int)ChainId.MainNet : 0), NullLogManager.Instance);
                bool           verified = ecdsa.Verify(
                    validTest.Sender,
                    transaction,
                    0);
                Assert.True(verified);
            }
            else
            {
                Assert.False(validator.IsWellFormed(transaction, spec));
            }
        }