public void NonGenericArrayEncoding2() { var exampleArray = new List <List <UInt256> >(); exampleArray.Add(new List <UInt256> { 1, 2, 3 }); exampleArray.Add(new List <UInt256> { 4, 5, 6 }); exampleArray.Add(new List <UInt256> { 7, 8, 9 }); exampleArray.Add(new List <UInt256> { 10, 11, 12 }); var encoded = SolidityUtil.AbiEncode("uint256[4][3]", exampleArray); var encodedHex = encoded.ToHexString(); var recode = SolidityUtil.AbiDecode <UInt256[][]>("uint256[4][3]", encoded); Assert.Equal(exampleArray[0][0], recode[0][0]); Assert.Equal(exampleArray[1][0], recode[1][0]); Assert.Equal(exampleArray[2][0], recode[2][0]); }
void TestConvert(string solType, object num) { var result = SolidityUtil.AbiEncode((solType, num)); var decoded = SolidityUtil.AbiDecode(solType, result); var expectedResult = ToInvariantString(num); var decodedResult = ToInvariantString(decoded); Assert.Equal(expectedResult, decodedResult); _output.WriteLine($"{solType}, {num.GetType()}, {expectedResult}, {decodedResult}"); }
public void NonGenericArrayEncoding() { var exampleArray = new List <UInt256>(); exampleArray.Add(3); exampleArray.Add(777); exampleArray.Add(3333); var encoded = SolidityUtil.AbiEncode("uint256[3]", exampleArray); var encodedHex = encoded.ToHexString(); var recode = SolidityUtil.AbiDecode <UInt256[]>("uint256[3]", encoded); Assert.Equal(exampleArray[0], recode[0]); Assert.Equal(exampleArray[1], recode[1]); Assert.Equal(exampleArray[2], recode[2]); }
public void MultiDimensionalArrayEncoding() { var exampleArray = ArrayExtensions.CreateJaggedArray <UInt256[][][]>(2, 6, 3); exampleArray[0][0][0] = 3; exampleArray[0][4][2] = 3333; exampleArray[0][2][1] = 777; var encoded = SolidityUtil.AbiEncode("uint256[2][6][3]", exampleArray); var encodedHex = encoded.ToHexString(); var recode = SolidityUtil.AbiDecode <UInt256[][][]>("uint256[2][6][3]", encoded); Assert.Equal(exampleArray[0][0][0], recode[0][0][0]); Assert.Equal(exampleArray[0][4][2], recode[0][4][2]); Assert.Equal(exampleArray[0][2][1], recode[0][2][1]); }
public void HashPersonalMessage(string expectedResult, string inputMsg) { var result = SolidityUtil.HashPersonalMessage(inputMsg).ToHexString(hexPrefix: true); Assert.Equal(expectedResult, result); }
public async Task MultiDim() { // Create our expected 3 dimensional array. var expected3D = ArrayExtensions.CreateJaggedArray <UInt256[][][]>(2, 6, 3); uint x = 0; for (uint i = 0; i < 2; i++) { for (uint j = 0; j < 6; j++) { for (uint k = 0; k < 3; k++) { expected3D[i][j][k] = x++; } } } var t1 = await _contract.arrayStaticMultiDim3DEcho(expected3D).Call(); // Create our expected 2 dimensional array. var expected2D = ArrayExtensions.CreateJaggedArray <UInt256[][]>(6, 3); x = 0; for (uint j = 0; j < 6; j++) { for (uint k = 0; k < 3; k++) { expected2D[j][k] = x++; } } var t2 = await _contract.arrayStaticMultiDim2DEcho(expected2D).Call(); // Encode and decode our 3D array to test re-encoding. var encoded = SolidityUtil.AbiEncode("uint256[2][6][3]", expected3D); var encodedHex = encoded.ToHexString(); var recode = SolidityUtil.AbiDecode <UInt256[][][]>("uint256[2][6][3]", encoded); Assert.AreEqual(expected3D[0][0][0], recode[0][0][0]); Assert.AreEqual(expected3D[1][5][2], recode[1][5][2]); Assert.AreEqual(expected3D[0][2][1], recode[0][2][1]); // Call our method that returns a static 3D array programmed in a contract. var rawData3D = await _contract.arrayStaticMultiDim3D().CallRaw(); var hex = rawData3D.ToHexString(); var decoded3D = SolidityUtil.AbiDecode <UInt256[][][]>("uint256[2][6][3]", rawData3D); Assert.AreEqual(expected3D[0][0][0], decoded3D[0][0][0]); Assert.AreEqual(expected3D[1][5][2], decoded3D[1][5][2]); Assert.AreEqual(expected3D[0][2][1], decoded3D[0][2][1]); Assert.AreEqual(hex, encodedHex); // Call our method that returns a static 2D array programmed in a contract. var rawData2D = await _contract.arrayStaticMultiDim2D().CallRaw(); var decoded2D = SolidityUtil.AbiDecode <UInt256[][]>("uint256[6][3]", rawData2D); Assert.AreEqual(expected2D[0][0], decoded2D[0][0]); Assert.AreEqual(expected2D[3][1], decoded2D[3][1]); Assert.AreEqual(expected2D[5][2], decoded2D[5][2]); }