Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public TransactionResult(BlockCapsule blockCapsule, int index, Protocol.Transact
TransactionCapsule capsule = new TransactionCapsule(tx);
byte[] txId = capsule.getTransactionId().getBytes();
hash = ByteArray.toJsonHex(txId);
nonce = ByteArray.toJsonHex(new byte[8]); // no value
nonce = "0x0"; // no value, QUANTITY type per Ethereum JSON-RPC spec
blockHash = ByteArray.toJsonHex(blockCapsule.getBlockId().getBytes());
blockNumber = ByteArray.toJsonHex(blockCapsule.getNum());
transactionIndex = ByteArray.toJsonHex(index);
Expand Down Expand Up @@ -133,7 +133,7 @@ public TransactionResult(Transaction tx, Wallet wallet) {
TransactionCapsule capsule = new TransactionCapsule(tx);
byte[] txId = capsule.getTransactionId().getBytes();
hash = ByteArray.toJsonHex(txId);
nonce = ByteArray.toJsonHex(new byte[8]); // no value
nonce = "0x0"; // no value, QUANTITY type per Ethereum JSON-RPC spec
blockHash = "0x";
blockNumber = "0x";
transactionIndex = "0x";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,18 @@ public class TransactionResultTest extends BaseTest {
private static final String OWNER_ADDRESS = "41548794500882809695a8a687866e76d4271a1abc";
private static final String CONTRACT_ADDRESS = "A0B4750E2CD76E19DCA331BF5D089B71C3C2798548";

// QUANTITY pattern from ethereum/execution-apis base-types schema (uint).
private static final String QUANTITY_PATTERN = "^0x(0|[1-9a-f][0-9a-f]*)$";

static {
Args.setParam(new String[] {"-d", dbPath()}, TestConstants.TEST_CONF);
}

private static void assertQuantity(String value) {
Assert.assertNotNull(value);
Assert.assertTrue("not a valid QUANTITY: " + value, value.matches(QUANTITY_PATTERN));
}

@Test
public void testBuildTransactionResultWithBlock() {
SmartContractOuterClass.TriggerSmartContract.Builder builder2 =
Expand All @@ -49,6 +57,8 @@ public void testBuildTransactionResultWithBlock() {
transactionResult.getHash());
Assert.assertEquals(transactionResult.getGasPrice(), "0x1");
Assert.assertEquals(transactionResult.getGas(), "0x64");
Assert.assertEquals("0x0", transactionResult.getNonce());
assertQuantity(transactionResult.getNonce());
}

@Test
Expand All @@ -65,7 +75,8 @@ public void testBuildTransactionResult() {
Assert.assertEquals("0x5691531881bc44adbc722060d85fdf29265823db8e884b0d104fcfbba253cf11",
transactionResult.getHash());
Assert.assertEquals(transactionResult.getGasPrice(), "0x");
Assert.assertEquals(transactionResult.getNonce(), "0x0000000000000000");
Assert.assertEquals("0x0", transactionResult.getNonce());
assertQuantity(transactionResult.getNonce());
}

}
Loading