Exemplo n.º 1
0
        public void TestAbiFunctionEncode()
        {
            string            abiJson = "{\"constant\": false,\"inputs\": [{\"name\": \"a1\",\"type\": \"uint256\"},{\"name\": \"a2\",\"type\": \"string\"}],\"name\": \"f1\",\"outputs\": [{\"name\": \"r1\",\"type\": \"address\"},{\"name\": \"r2\",\"type\": \"bytes\"}],\"payable\": false,\"stateMutability\": \"nonpayable\",\"type\": \"function\"}";
            AbiFuncationCoder coder   = new AbiFuncationCoder(abiJson);
            var encodeData            = coder.Encode(1, "foo");

            var data = "0x27fcbb2f000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000003666f6f0000000000000000000000000000000000000000000000000000000000";

            Assert.True(encodeData.SequenceEqual(data.ToBytes()));
        }
Exemplo n.º 2
0
        public void TestAbiFunctionDecode()
        {
            string            outputData = "0x0000000000000000000000004c6f3ca686c053354a83c030e80d2ee0a000b0cf000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005c073850000000000000000000000000000000000000000000000000000000005c073850000000000000000000000000000000000000000000000000000000005c073850";
            string            abiJson    = "{\"constant\": true,\"inputs\": [{\"name\": \"_tokenId\",\"type\": \"uint256\"}],\"name\": \"getMetadata\",\"outputs\": [{\"name\": \"\",\"type\": \"address\"},{\"name\": \"\",\"type\": \"uint8\"},{\"name\": \"\",\"type\": \"bool\"},{\"name\": \"\",\"type\": \"bool\"},{\"name\": \"\",\"type\": \"uint64\"},{\"name\": \"\",\"type\": \"uint64\"},{\"name\": \"\",\"type\": \"uint64\"}],\"payable\": false,\"stateMutability\": \"view\",\"type\": \"function\"}";
            AbiFuncationCoder coder      = new AbiFuncationCoder(abiJson);
            var output = coder.Decode(outputData.ToBytes());

            Assert.True((output[0].Result as string).Equals("0x4c6f3ca686c053354a83c030e80d2ee0a000b0cf"));
            Assert.True(((BigInteger)output[1].Result).Equals(new BigInteger(5)));
            Assert.True(((bool)output[2].Result).Equals(false));
            Assert.True(((bool)output[3].Result).Equals(false));
            Assert.True(((BigInteger)output[4].Result).Equals(new BigInteger(1543977040)));
            Assert.True(((BigInteger)output[5].Result).Equals(new BigInteger(1543977040)));
            Assert.True(((BigInteger)output[6].Result).Equals(new BigInteger(1543977040)));
        }