@@ -18,6 +18,7 @@ describe('TxHistoryController', () => {
1818 let rskNodeService : RskNodeService ;
1919 let storeTransaction : sinon . SinonStub ;
2020 let getTransactionHistoryByAddress : sinon . SinonStub ;
21+ let getTransactionByHash : sinon . SinonStub ;
2122 let getTx : sinon . SinonStub ;
2223 let getRskTransaction : sinon . SinonStub ;
2324 let context : any ;
@@ -33,9 +34,11 @@ describe('TxHistoryController', () => {
3334 getRskTransaction = rskNodeService . getTransaction as sinon . SinonStub ;
3435 storeTransaction = txHistoryService . storeTransaction as sinon . SinonStub ;
3536 getTransactionHistoryByAddress = txHistoryService . getTransactionHistoryByAddress as sinon . SinonStub ;
37+ getTransactionByHash = txHistoryService . getTransactionByHash as sinon . SinonStub ;
3638
3739 getTx . resolves ( { } ) ;
3840 getRskTransaction . resolves ( { } ) ;
41+ getTransactionByHash . resolves ( null ) ;
3942
4043 controller = new TxHistoryController (
4144 bitcoinService ,
@@ -115,6 +118,32 @@ describe('TxHistoryController', () => {
115118 sinon . assert . notCalled ( storeTransaction ) ;
116119 expect ( response . statusCode ) . to . equal ( 200 ) ;
117120 } ) ;
121+
122+ it ( 'should return 200 and not store when transaction already exists in database' , async ( ) => {
123+ const txHistory : TxHistory = {
124+ userAddress : '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb0' ,
125+ txHash : '0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd' ,
126+ providerHash : 'ExistingTxHash' ,
127+ fromTokenName : 'BTC' ,
128+ fromNetworkName : 'Bitcoin' ,
129+ toTokenName : 'RBTC' ,
130+ toNetworkName : 'Rootstock' ,
131+ fromAmount : '0.001' ,
132+ toAmount : '0.0009' ,
133+ date : new Date ( '2024-01-03' ) ,
134+ sdkProvider : 'FLYOVER' ,
135+ } as TxHistory ;
136+
137+ getTransactionByHash . resolves ( txHistory ) ;
138+
139+ const response = await controller . storeTransaction ( txHistory ) ;
140+
141+ sinon . assert . calledOnce ( getTransactionByHash ) ;
142+ sinon . assert . notCalled ( getTx ) ;
143+ sinon . assert . notCalled ( getRskTransaction ) ;
144+ sinon . assert . notCalled ( storeTransaction ) ;
145+ expect ( response . statusCode ) . to . equal ( 200 ) ;
146+ } ) ;
118147 } ) ;
119148
120149 describe ( 'getTransactionHistory' , ( ) => {
0 commit comments