Beispiel #1
0
        public void Test(TransactionTest test)
        {
            EthereumSigner ethereumSigner  = new EthereumSigner(OlympicSpecProvider.Instance, NullLogManager.Instance);
            Transaction    decodedUnsigned = Rlp.Decode <Transaction>(test.Unsigned);

            Assert.AreEqual(test.Value, decodedUnsigned.Value, "value");
            Assert.AreEqual(test.GasPrice, decodedUnsigned.GasPrice, "gasPrice");
            Assert.AreEqual(test.StartGas, decodedUnsigned.GasLimit, "gasLimit");
            Assert.AreEqual(test.Data, decodedUnsigned.Data ?? decodedUnsigned.Init, "data");
            Assert.AreEqual(test.To, decodedUnsigned.To, "to");
            Assert.AreEqual(test.Nonce, decodedUnsigned.Nonce, "nonce");

            Transaction decodedSigned = Rlp.Decode <Transaction>(test.Signed);

            ethereumSigner.Sign(test.PrivateKey, decodedUnsigned, 0);
            Assert.AreEqual(decodedSigned.Signature.R, decodedUnsigned.Signature.R, "R");
            BigInteger expectedS = decodedSigned.Signature.S.ToUnsignedBigInteger();
            BigInteger actualS   = decodedUnsigned.Signature.S.ToUnsignedBigInteger();
            BigInteger otherS    = EthereumSigner.LowSTransform - actualS;

            // test does not use normalized signature
            if (otherS != expectedS && actualS != expectedS)
            {
                throw new Exception("S is wrong");
            }

            int vToCompare = decodedUnsigned.Signature.V;

            if (otherS == decodedSigned.Signature.S.ToUnsignedBigInteger())
            {
                vToCompare = vToCompare == 27 ? 28 : 27;
            }

            Assert.AreEqual(decodedSigned.Signature.V, vToCompare, "V");
        }
            public On AddPendingTransaction(PrivateKey nodeKey)
            {
                Transaction transaction = new Transaction();

                transaction.Value         = 1;
                transaction.To            = TestObject.AddressC;
                transaction.GasLimit      = 30000;
                transaction.GasPrice      = 20.GWei();
                transaction.Nonce         = _currentNonce++;
                transaction.SenderAddress = TestObject.PrivateKeyD.Address;
                transaction.Hash          = Transaction.CalculateHash(transaction);
                _ethereumSigner.Sign(TestObject.PrivateKeyD, transaction, 1);
                _pools[nodeKey].AddTransaction(transaction, 1);

                return(this);
            }
Beispiel #3
0
        public void Sign_and_recover()
        {
            EthereumSigner ethereumSigner = new EthereumSigner(OlympicSpecProvider.Instance, NullLogManager.Instance);

            Keccak     message    = Keccak.Compute("Test message");
            PrivateKey privateKey = new PrivateKey(_cryptoRandom.GenerateRandomBytes(32));
            Signature  signature  = ethereumSigner.Sign(privateKey, message);

            Assert.AreEqual(privateKey.Address, ethereumSigner.RecoverAddress(signature, message));
        }
Beispiel #4
0
        public void Sign_and_recover()
        {
            EthereumSigner ethereumSigner = new EthereumSigner(OlympicSpecProvider.Instance, NullLogManager.Instance);

            Keccak     message    = Keccak.Compute("Test message");
            PrivateKey privateKey = Build.A.PrivateKey.TestObject;
            Signature  signature  = ethereumSigner.Sign(privateKey, message);

            Assert.AreEqual(privateKey.Address, ethereumSigner.RecoverAddress(signature, message));
        }
Beispiel #5
0
        public void Signature_test_olympic(int blockNumber)
        {
            EthereumSigner signer = new EthereumSigner(OlympicSpecProvider.Instance, NullLogManager.Instance);
            PrivateKey     key    = Build.A.PrivateKey.TestObject;
            Transaction    tx     = Build.A.Transaction.TestObject;

            signer.Sign(key, tx, blockNumber);
            Address address = signer.RecoverAddress(tx, blockNumber);

            Assert.AreEqual(key.Address, address);
        }
Beispiel #6
0
        public void Sign_goerli()
        {
            EthereumSigner signer = new EthereumSigner(GoerliSpecProvider.Instance, LimboLogs.Instance);
            PrivateKey     key    = Build.A.PrivateKey.TestObject;
            Transaction    tx     = Build.A.Transaction.TestObject;

            signer.Sign(key, tx, 1);
            Address address = signer.RecoverAddress(tx, 1);

            Assert.AreEqual(key.Address, address);
        }
Beispiel #7
0
        public void Signature_test_ropsten(uint blockNumber)
        {
            EthereumSigner signer = new EthereumSigner(RopstenSpecProvider.Instance, LimboLogs.Instance);
            PrivateKey     key    = Build.A.PrivateKey.TestObject;
            Transaction    tx     = Build.A.Transaction.TestObject;

            signer.Sign(key, tx, blockNumber);
            Address address = signer.RecoverAddress(tx, blockNumber);

            Assert.AreEqual(key.Address, address);
        }
Beispiel #8
0
        private static string SendEth(Address address, decimal amount)
        {
            UInt256 blockNumber = _client.Post <UInt256>("eth_blockNumber").Result;

            Transaction tx = new Transaction();

            tx.Value         = (UInt256)(amount * (decimal)1.Ether());
            tx.To            = address;
            tx.GasLimit      = 21000;
            tx.GasPrice      = (UInt256)(_engine.GetValue("gasPrice").AsNumber());
            tx.Nonce         = (ulong)_client.Post <BigInteger>("eth_getTransactionCount", _nodeKey.Address, blockNumber).Result;
            tx.SenderAddress = _nodeKey.Address;

            int            chainId = _client.Post <int>("net_version").Result;
            EthereumSigner signer  = new EthereumSigner(new SingleReleaseSpecProvider(ConstantinopleFix.Instance, chainId), _logManager);

            signer.Sign(_nodeKey, tx, blockNumber);

            Keccak keccak = _client.Post <Keccak>("eth_sendRawTransaction", Rlp.Encode(tx, false).Bytes).Result;

            return(_serializer.Serialize(keccak, true));
        }