|
9 | 9 | import org.tron.core.Constant; |
10 | 10 | import org.tron.core.Wallet; |
11 | 11 | import org.tron.core.capsule.BlockCapsule; |
| 12 | +import org.tron.core.capsule.TransactionCapsule; |
12 | 13 | import org.tron.core.config.args.Args; |
13 | 14 | import org.tron.core.services.jsonrpc.types.TransactionResult; |
14 | 15 | import org.tron.protos.Protocol; |
| 16 | +import org.tron.protos.contract.SmartContractOuterClass; |
15 | 17 |
|
16 | 18 | public class TransactionResultTest extends BaseTest { |
17 | 19 |
|
18 | 20 | @Resource |
19 | 21 | private Wallet wallet; |
20 | 22 |
|
| 23 | + private static final String OWNER_ADDRESS = "41548794500882809695a8a687866e76d4271a1abc"; |
| 24 | + private static final String CONTRACT_ADDRESS = "A0B4750E2CD76E19DCA331BF5D089B71C3C2798548"; |
| 25 | + |
21 | 26 | static { |
22 | | - Args.setParam(new String[]{"-d", dbPath()}, Constant.TEST_CONF); |
| 27 | + Args.setParam(new String[] {"-d", dbPath()}, Constant.TEST_CONF); |
23 | 28 | } |
24 | 29 |
|
25 | 30 | @Test |
26 | 31 | public void testBuildTransactionResultWithBlock() { |
27 | | - Protocol.Transaction.raw.Builder raw = Protocol.Transaction.raw.newBuilder().addContract( |
28 | | - Protocol.Transaction.Contract.newBuilder().setType( |
29 | | - Protocol.Transaction.Contract.ContractType.TriggerSmartContract)); |
30 | | - Protocol.Transaction transaction = Protocol.Transaction.newBuilder().setRawData(raw).build(); |
| 32 | + SmartContractOuterClass.TriggerSmartContract.Builder builder2 = |
| 33 | + SmartContractOuterClass.TriggerSmartContract.newBuilder() |
| 34 | + .setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(OWNER_ADDRESS))) |
| 35 | + .setContractAddress(ByteString.copyFrom(ByteArray.fromHexString(CONTRACT_ADDRESS))); |
| 36 | + TransactionCapsule transactionCapsule = new TransactionCapsule(builder2.build(), |
| 37 | + Protocol.Transaction.Contract.ContractType.TriggerSmartContract); |
| 38 | + Protocol.Transaction transaction = transactionCapsule.getInstance(); |
31 | 39 | BlockCapsule blockCapsule = new BlockCapsule(Protocol.Block.newBuilder().setBlockHeader( |
32 | 40 | Protocol.BlockHeader.newBuilder().setRawData(Protocol.BlockHeader.raw.newBuilder() |
33 | 41 | .setParentHash(ByteString.copyFrom(ByteArray.fromHexString( |
34 | 42 | "0304f784e4e7bae517bcab94c3e0c9214fb4ac7ff9d7d5a937d1f40031f87b82"))) |
35 | 43 | .setNumber(9))).addTransactions(transaction).build()); |
36 | 44 |
|
37 | | - TransactionResult transactionResult = new TransactionResult(blockCapsule,0, transaction, |
38 | | - 100,1, wallet); |
| 45 | + TransactionResult transactionResult = new TransactionResult(blockCapsule, 0, transaction, |
| 46 | + 100, 1, wallet); |
39 | 47 | Assert.assertEquals(transactionResult.getBlockNumber(), "0x9"); |
40 | | - Assert.assertEquals(transactionResult.getHash(), |
41 | | - "0xdebef90d0a8077620711b1b5af2b702665887ddcbf80868108026e1ab5e0bfb7"); |
| 48 | + Assert.assertEquals("0x5691531881bc44adbc722060d85fdf29265823db8e884b0d104fcfbba253cf11", |
| 49 | + transactionResult.getHash()); |
42 | 50 | Assert.assertEquals(transactionResult.getGasPrice(), "0x1"); |
43 | 51 | Assert.assertEquals(transactionResult.getGas(), "0x64"); |
44 | 52 | } |
45 | 53 |
|
46 | 54 | @Test |
47 | 55 | public void testBuildTransactionResult() { |
48 | | - Protocol.Transaction.raw.Builder raw = Protocol.Transaction.raw.newBuilder().addContract( |
49 | | - Protocol.Transaction.Contract.newBuilder().setType( |
50 | | - Protocol.Transaction.Contract.ContractType.TriggerSmartContract)); |
51 | | - Protocol.Transaction transaction = Protocol.Transaction.newBuilder().setRawData(raw).build(); |
52 | | - TransactionResult transactionResult = new TransactionResult(transaction, wallet); |
53 | | - Assert.assertEquals(transactionResult.getHash(), |
54 | | - "0xdebef90d0a8077620711b1b5af2b702665887ddcbf80868108026e1ab5e0bfb7"); |
| 56 | + SmartContractOuterClass.TriggerSmartContract.Builder builder2 = |
| 57 | + SmartContractOuterClass.TriggerSmartContract.newBuilder() |
| 58 | + .setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(OWNER_ADDRESS))) |
| 59 | + .setContractAddress(ByteString.copyFrom(ByteArray.fromHexString(CONTRACT_ADDRESS))); |
| 60 | + TransactionCapsule transactionCapsule = new TransactionCapsule(builder2.build(), |
| 61 | + Protocol.Transaction.Contract.ContractType.TriggerSmartContract); |
| 62 | + |
| 63 | + TransactionResult transactionResult = |
| 64 | + new TransactionResult(transactionCapsule.getInstance(), wallet); |
| 65 | + Assert.assertEquals("0x5691531881bc44adbc722060d85fdf29265823db8e884b0d104fcfbba253cf11", |
| 66 | + transactionResult.getHash()); |
55 | 67 | Assert.assertEquals(transactionResult.getGasPrice(), "0x"); |
56 | 68 | Assert.assertEquals(transactionResult.getNonce(), "0x0000000000000000"); |
57 | 69 | } |
|
0 commit comments