1
1
package org .cardanofoundation .rosetta .api .block .service ;
2
2
3
+ import java .math .BigInteger ;
4
+ import jakarta .persistence .EntityManager ;
5
+ import jakarta .persistence .PersistenceContext ;
6
+
3
7
import org .springframework .beans .factory .annotation .Autowired ;
4
8
5
9
import org .junit .jupiter .api .Test ;
8
12
import org .cardanofoundation .rosetta .api .account .model .domain .Utxo ;
9
13
import org .cardanofoundation .rosetta .api .block .model .domain .Block ;
10
14
import org .cardanofoundation .rosetta .api .block .model .domain .BlockTx ;
15
+ import org .cardanofoundation .rosetta .api .block .model .entity .BlockEntity ;
16
+ import org .cardanofoundation .rosetta .api .block .model .entity .UtxoKey ;
11
17
import org .cardanofoundation .rosetta .common .services .ProtocolParamService ;
12
- import org .cardanofoundation .rosetta .testgenerator .common .TestConstants ;
13
- import org .cardanofoundation .rosetta .testgenerator .common .TestTransactionNames ;
14
18
import org .cardanofoundation .rosetta .testgenerator .common .TransactionBlockDetails ;
15
19
16
20
import static org .assertj .core .api .Assertions .assertThat ;
21
+ import static org .cardanofoundation .rosetta .testgenerator .common .TestConstants .ACCOUNT_BALANCE_LOVELACE_AMOUNT ;
22
+ import static org .cardanofoundation .rosetta .testgenerator .common .TestConstants .SENDER_2_ADDRESS ;
23
+ import static org .cardanofoundation .rosetta .testgenerator .common .TestConstants .TEST_ACCOUNT_ADDRESS ;
24
+ import static org .cardanofoundation .rosetta .testgenerator .common .TestTransactionNames .SIMPLE_TRANSACTION ;
17
25
import static org .junit .jupiter .api .Assertions .assertEquals ;
26
+ import static org .junit .jupiter .api .Assertions .assertNotNull ;
18
27
19
28
class BlockServiceImplIntTest extends IntegrationTest {
20
29
21
30
@ Autowired
22
31
private BlockService blockService ;
23
- final TransactionBlockDetails simpleTx = generatedDataMap .get (
24
- TestTransactionNames .SIMPLE_TRANSACTION .getName ());
32
+ final TransactionBlockDetails simpleTx = generatedDataMap .get (SIMPLE_TRANSACTION .getName ());
33
+
34
+ @ PersistenceContext
35
+ private EntityManager entityManager ;
25
36
26
37
27
38
@ Autowired
@@ -31,18 +42,17 @@ class BlockServiceImplIntTest extends IntegrationTest {
31
42
void getBlockWithTransaction_Test () {
32
43
//given
33
44
//when
34
- Block block = blockService .findBlock (simpleTx .blockNumber (),
35
- simpleTx .blockHash ());
45
+ Block block = blockService .findBlock (simpleTx .blockNumber (), simpleTx .blockHash ());
36
46
37
47
//then
38
48
assertEquals (simpleTx .blockHash (), block .getHash ());
39
49
assertEquals (simpleTx .blockNumber (), block .getSlotNo ());
40
50
assertEquals (1 , block .getTransactions ().size ());
41
51
42
52
Utxo receiverUtxoDto = block .getTransactions ().getFirst ().getOutputs ().getFirst ();
43
- assertEquals (TestConstants . TEST_ACCOUNT_ADDRESS , receiverUtxoDto .getOwnerAddr ());
53
+ assertEquals (TEST_ACCOUNT_ADDRESS , receiverUtxoDto .getOwnerAddr ());
44
54
assertEquals (simpleTx .txHash (), receiverUtxoDto .getTxHash ());
45
- assertEquals (TestConstants . ACCOUNT_BALANCE_LOVELACE_AMOUNT ,
55
+ assertEquals (ACCOUNT_BALANCE_LOVELACE_AMOUNT ,
46
56
receiverUtxoDto .getLovelaceAmount ().toString ());
47
57
48
58
}
@@ -70,17 +80,36 @@ void getBlockTransaction_Test() {
70
80
assertEquals (0 , tx .getPoolRetirements ().size ());
71
81
assertEquals (0 , tx .getDelegations ().size ());
72
82
83
+ assertNotNull (entityManager );
84
+ BlockEntity fromBlockB = entityManager
85
+ .createQuery ("from BlockEntity b where b.number=:block" , BlockEntity .class )
86
+ .setParameter ("block" , simpleTx .blockNumber ())
87
+ .getSingleResult ();
88
+
73
89
Utxo inUtxo = tx .getInputs ().getFirst ();
90
+ UtxoKey expectedInputKey = fromBlockB .getTransactions ().getFirst ().getInputKeys ().getFirst ();
91
+
92
+ assertEquals (SENDER_2_ADDRESS , inUtxo .getOwnerAddr ());
93
+ assertEquals (expectedInputKey .getTxHash (), inUtxo .getTxHash ());
94
+ assertEquals (expectedInputKey .getOutputIndex (), inUtxo .getOutputIndex ());
95
+
96
+ Utxo outUtxo1 = tx .getOutputs ().getFirst ();
97
+ assertEquals (TEST_ACCOUNT_ADDRESS , outUtxo1 .getOwnerAddr ());
98
+ assertEquals (blockTxHash , outUtxo1 .getTxHash ());
99
+ assertEquals (ACCOUNT_BALANCE_LOVELACE_AMOUNT , outUtxo1 .getLovelaceAmount ().toString ());
100
+
101
+ Utxo outUtxo2 = tx .getOutputs ().getLast ();
102
+ assertEquals (SENDER_2_ADDRESS , outUtxo2 .getOwnerAddr ());
103
+ assertEquals (blockTxHash , outUtxo2 .getTxHash ());
74
104
75
- //TODO saa: how to check?
76
- assertEquals (TestConstants .SENDER_2_ADDRESS , inUtxo .getOwnerAddr ());
77
- // assertEquals(blockTxHash, inUtxo.getTxHash());
105
+ // init deposit was 1000 ADA for the account1: addr_test1qp73lju...
106
+ // (@see test-data-generator/README.md)
107
+ BigInteger initAmountSender1 = BigInteger .valueOf (1000 * 1_000_000 ); //ADA to lovelace
108
+ BigInteger expected = initAmountSender1
109
+ .add (fromBlockB .getTotalFees ().negate ()) //fee
110
+ .add (new BigInteger (ACCOUNT_BALANCE_LOVELACE_AMOUNT ).negate ()); //sent amount
78
111
79
- Utxo outUtxo = tx .getOutputs ().getFirst ();
80
- assertEquals (TestConstants .TEST_ACCOUNT_ADDRESS , outUtxo .getOwnerAddr ());
81
- assertEquals (blockTxHash , outUtxo .getTxHash ());
82
- assertEquals (TestConstants .ACCOUNT_BALANCE_LOVELACE_AMOUNT ,
83
- outUtxo .getLovelaceAmount ().toString ());
112
+ assertEquals (expected , outUtxo2 .getLovelaceAmount ());
84
113
85
114
}
86
115
0 commit comments