Untitled
unknown
plain_text
2 years ago
2.0 kB
6
Indexable
val function = EthereumAbiFunction("sam") // add params assertEquals(0, function.addParamBytes("0x64617665".toHexByteArray(), false)) assertEquals(1, function.addParamBool(true, false)) assertEquals(2, function.addParamArray(false)) assertEquals(0, function.addInArrayParamUInt256(2, "0x01".toHexByteArray())) assertEquals(1, function.addInArrayParamUInt256(2, "0x02".toHexByteArray())) assertEquals(2, function.addInArrayParamUInt256(2, "0x03".toHexByteArray())) assertEquals(0, function.addParamUInt64(0, true)) // check signature assertEquals("sam(bytes,bool,uint256[])", function.type) // encode val encoded = EthereumAbi.encode(function) assertEquals("0xa5643bf2" + "0000000000000000000000000000000000000000000000000000000000000060" + "0000000000000000000000000000000000000000000000000000000000000001" + "00000000000000000000000000000000000000000000000000000000000000a0" + "0000000000000000000000000000000000000000000000000000000000000004" + "6461766500000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000003" + "0000000000000000000000000000000000000000000000000000000000000001" + "0000000000000000000000000000000000000000000000000000000000000002" + "0000000000000000000000000000000000000000000000000000000000000003", Numeric.toHexString(encoded)) // original output value assertEquals(0, function.getParamUInt64(0, true)) // decode output val encodedOutput = "0000000000000000000000000000000000000000000000000000000000000045".toHexByteArray() val decodeRes = EthereumAbi.decodeOutput(function, encodedOutput) assertEquals(true, decodeRes) // new output value assertEquals(0x45, function.getParamUInt64(0, true))
Editor is loading...