34
34
import java .util .*;
35
35
36
36
class RegisterBtcTransactionIT {
37
+ public static final long RSK_EXECUTION_BLOCK_NUMBER = 1000L ;
38
+ public static final long RSK_EXECUTION_BLOCK_TIMESTAMP = 10L ;
37
39
private final BridgeConstants bridgeConstants = BridgeMainNetConstants .getInstance ();
38
40
private final NetworkParameters btcNetworkParams = bridgeConstants .getBtcParams ();
39
41
private final BridgeSupportBuilder bridgeSupportBuilder = BridgeSupportBuilder .builder ();
40
42
private final ActivationConfig .ForBlock activations = ActivationConfigsForTest .all ().forBlock (0 );
41
43
private final Transaction rskTx = TransactionUtils .createTransaction ();
42
44
private final Coin minimumPeginValue = bridgeConstants .getMinimumPeginTxValue (activations );
43
- private final Block rskExecutionBlock = getRskExecutionBlock ();
45
+ private final Block rskExecutionBlock = getRskExecutionBlock (RSK_EXECUTION_BLOCK_NUMBER , RSK_EXECUTION_BLOCK_TIMESTAMP );
44
46
private Repository repository ;
45
47
private FederationSupport federationSupport ;
46
48
private BridgeStorageProvider bridgeStorageProvider ;
@@ -60,20 +62,17 @@ void setUp() throws Exception{
60
62
StorageAccessor bridgeStorageAccessor = new BridgeStorageAccessorImpl (repository );
61
63
62
64
FeePerKbStorageProvider feePerKbStorageProvider = new FeePerKbStorageProviderImpl (bridgeStorageAccessor );
63
- FeePerKbSupport feePerKbSupport = new FeePerKbSupportImpl (
64
- bridgeConstants .getFeePerKbConstants (),
65
- feePerKbStorageProvider
66
- );
65
+ FeePerKbSupport feePerKbSupport = new FeePerKbSupportImpl (bridgeConstants .getFeePerKbConstants (), feePerKbStorageProvider );
67
66
67
+ FederationStorageProvider federationStorageProvider = new FederationStorageProviderImpl (bridgeStorageAccessor );
68
68
Federation federation = P2shErpFederationBuilder .builder ().build ();
69
- FederationStorageProvider federationStorageProvider = createFederationStorageProvider (repository );
70
69
federationStorageProvider .setNewFederation (federation );
71
70
FederationConstants federationConstants = bridgeConstants .getFederationConstants ();
72
71
federationSupport = FederationSupportBuilder .builder ()
73
- .withFederationConstants (federationConstants )
74
- .withFederationStorageProvider (federationStorageProvider )
75
- .withActivations (activations )
76
- .build ();
72
+ .withFederationConstants (federationConstants )
73
+ .withFederationStorageProvider (federationStorageProvider )
74
+ .withActivations (activations )
75
+ .build ();
77
76
78
77
bridgeStorageProvider = new BridgeStorageProvider (repository , PrecompiledContracts .BRIDGE_ADDR , btcNetworkParams , activations );
79
78
BtcBlockStoreWithCache .Factory btcBlockStoreFactory = new RepositoryBtcBlockStoreWithCache .Factory (btcNetworkParams , 100 , 100 );
@@ -93,42 +92,41 @@ void setUp() throws Exception{
93
92
94
93
recreateChainFromPmt (btcBlockStoreWithCache , chainHeight , pmtWithTransactions , btcBlockWithPmtHeight , btcNetworkParams );
95
94
bridgeStorageProvider .save ();
95
+
96
96
bridgeSupport = bridgeSupportBuilder
97
- .withBridgeConstants (bridgeConstants )
98
- .withProvider (bridgeStorageProvider )
99
- .withActivations (activations )
100
- .withEventLogger (bridgeEventLogger )
101
- .withFederationSupport (federationSupport )
102
- .withFeePerKbSupport (feePerKbSupport )
103
- .withExecutionBlock (rskExecutionBlock )
104
- .withBtcBlockStoreFactory (btcBlockStoreFactory )
105
- .withRepository (repository )
106
- .withBtcLockSenderProvider (btcLockSenderProvider )
107
- .build ();
97
+ .withBridgeConstants (bridgeConstants )
98
+ .withProvider (bridgeStorageProvider )
99
+ .withActivations (activations )
100
+ .withEventLogger (bridgeEventLogger )
101
+ .withFederationSupport (federationSupport )
102
+ .withFeePerKbSupport (feePerKbSupport )
103
+ .withExecutionBlock (rskExecutionBlock )
104
+ .withBtcBlockStoreFactory (btcBlockStoreFactory )
105
+ .withRepository (repository )
106
+ .withBtcLockSenderProvider (btcLockSenderProvider )
107
+ .build ();
108
108
}
109
109
110
110
@ Test
111
111
void registerBtcTransaction_forALegacyBtcTransaction_shouldRegisterTheNewUtxoAndTransferTheRbtcBalance () throws Exception {
112
- // Arrange
113
- TransactionOutput output = bitcoinTransaction .getOutput (0 );
114
- List <UTXO > expectedFederationUtxos = Collections .singletonList (utxoOf (bitcoinTransaction , output ));
115
-
116
- co .rsk .core .Coin receiverBalance = repository .getBalance (rskReceiver );
117
- co .rsk .core .Coin expectedReceiverBalance = receiverBalance .add (co .rsk .core .Coin .fromBitcoin (minimumPeginValue ));
118
-
119
112
// Act
120
113
bridgeSupport .registerBtcTransaction (rskTx , bitcoinTransaction .bitcoinSerialize (), btcBlockWithPmtHeight , pmtWithTransactions .bitcoinSerialize ());
121
114
bridgeSupport .save ();
122
115
123
116
// Assert
124
117
Optional <Long > heightIfBtcTxHashIsAlreadyProcessed = bridgeStorageProvider .getHeightIfBtcTxhashIsAlreadyProcessed (bitcoinTransaction .getHash ());
125
118
assertTrue (heightIfBtcTxHashIsAlreadyProcessed .isPresent ());
126
- assertEquals (rskExecutionBlock .getNumber (), heightIfBtcTxHashIsAlreadyProcessed .get ());
119
+ assertEquals (RSK_EXECUTION_BLOCK_NUMBER , heightIfBtcTxHashIsAlreadyProcessed .get ());
120
+
121
+ int outputIndex = 0 ;
122
+ TransactionOutput output = bitcoinTransaction .getOutput (outputIndex );
123
+ List <UTXO > expectedFederationUtxos = Collections .singletonList (utxoOf (bitcoinTransaction , output ));
127
124
assertEquals (expectedFederationUtxos , federationSupport .getActiveFederationBtcUTXOs ());
125
+
126
+ co .rsk .core .Coin expectedReceiverBalance = co .rsk .core .Coin .fromBitcoin (output .getValue ());
128
127
assertEquals (expectedReceiverBalance , repository .getBalance (rskReceiver ));
129
128
130
129
assertLogPegInBtc ();
131
-
132
130
}
133
131
134
132
@ Test
@@ -151,12 +149,12 @@ void registerBtc_forARepeatedLegacyBtcTransaction_shouldNotPerformAnyChange() th
151
149
152
150
private static UTXO utxoOf (BtcTransaction bitcoinTransaction , TransactionOutput output ) {
153
151
return new UTXO (
154
- bitcoinTransaction .getHash (),
155
- output .getIndex (),
156
- output .getValue (),
157
- 0 ,
158
- bitcoinTransaction .isCoinBase (),
159
- output .getScriptPubKey ()
152
+ bitcoinTransaction .getHash (),
153
+ output .getIndex (),
154
+ output .getValue (),
155
+ 0 ,
156
+ bitcoinTransaction .isCoinBase (),
157
+ output .getScriptPubKey ()
160
158
);
161
159
}
162
160
0 commit comments