Skip to content

Commit

Permalink
feat: add missing loadTransactions test
Browse files Browse the repository at this point in the history
  • Loading branch information
mahnunchik committed Mar 8, 2024
1 parent caf88ce commit 7575559
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
65 changes: 65 additions & 0 deletions test/fixtures/txs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"txs": [
{
"id": "7E112CF31CC31D1F500E43FEB89DF497E202082BA7F7DAE7B4ADCF143205045B",
"from": "rpJEDJy8pYSEmuKnqwQQEu2uGYcK5QRTjF",
"fromCurrency": "XRP",
"to": "rh67d9kPXX5ewqBDXoYKY7V4qQkf1EeHkL",
"toCurrency": "XRP",
"destinationTag": 123,
"fee": "0.000012",
"amount": "0.000001",
"timestamp": "2024-02-14T16:36:10.000Z",
"status": true
},
{
"id": "7CA5C46F081848653C2D4628B28A72F642F2A11648E78045BDD15C2ABCD513F7",
"from": "rBiBFHF9mt8EC65nJLzGy2NaDWMJNLAyD3",
"fromCurrency": "XRP",
"to": "rpJEDJy8pYSEmuKnqwQQEu2uGYcK5QRTjF",
"toCurrency": "XRP",
"destinationTag": 3,
"fee": "0.000012",
"amount": "0.000001",
"timestamp": "2024-01-10T13:17:52.000Z",
"status": true
},
{
"id": "32BEBC9AD168C32A12B330D2CEA18788E9EB76363486ECE8D6FE20CD3F806315",
"from": "rpJEDJy8pYSEmuKnqwQQEu2uGYcK5QRTjF",
"fromCurrency": "XRP",
"to": "rh67d9kPXX5ewqBDXoYKY7V4qQkf1EeHkL",
"toCurrency": "XRP",
"destinationTag": 111,
"fee": "0.000012",
"amount": "0.000002",
"timestamp": "2024-01-10T12:44:20.000Z",
"status": true
},
{
"id": "8A50C5311C104A5CBF37060D36CB6E067938CEB5446C715A42CC2BAAA7754099",
"from": "rBiBFHF9mt8EC65nJLzGy2NaDWMJNLAyD3",
"fromCurrency": "XRP",
"to": "rpJEDJy8pYSEmuKnqwQQEu2uGYcK5QRTjF",
"toCurrency": "XRP",
"destinationTag": 6666,
"fee": "0.000012",
"amount": "0.000001",
"timestamp": "2024-01-10T12:40:52.000Z",
"status": true
},
{
"id": "4531732008A1841C46ABA924BCF1D467CB96F5FAAEAA7CACD2D7314723F13B96",
"from": "rBiBFHF9mt8EC65nJLzGy2NaDWMJNLAyD3",
"fromCurrency": "XRP",
"to": "rpJEDJy8pYSEmuKnqwQQEu2uGYcK5QRTjF",
"toCurrency": "XRP",
"destinationTag": 555,
"fee": "0.006997",
"amount": "0.000001",
"timestamp": "2024-01-10T12:37:02.000Z",
"status": true
}
],
"limit": 5
}
41 changes: 41 additions & 0 deletions test/wallet.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { Amount } from '@coinspace/cs-common';
import Wallet from '@coinspace/cs-ripple-wallet';
import assert from 'node:assert/strict';
import fs from 'node:fs/promises';
import sinon from 'sinon';

const TXS = JSON.parse(await fs.readFile('./test/fixtures/txs.json', 'utf8'));

// eslint-disable-next-line max-len
const RANDOM_SEED = Buffer.from('2b48a48a752f6c49772bf97205660411cd2163fe6ce2de19537e9c94d3648c85c0d7f405660c20253115aaf1799b1c41cdd62b4cfbb6845bc9475495fc64b874', 'hex');
const RANDOM_SEED_PUB_KEY = 'rpJEDJy8pYSEmuKnqwQQEu2uGYcK5QRTjF';
Expand Down Expand Up @@ -884,4 +887,42 @@ describe('Ripple Wallet', () => {
assert.equal(id, '123456');
});
});

describe('loadTransactions', () => {
it('should load transactions (coin)', async () => {
sinon.stub(defaultOptions, 'request')
.withArgs({
seed: 'device',
method: 'GET',
url: `api/v1/account/${RANDOM_ADDRESS}`,
baseURL: 'node',
headers: sinon.match.any,
}).resolves({
balance: 12.345,
sequence: 1,
isActive: true,
})
.withArgs({
seed: 'device',
method: 'GET',
url: `api/v1/account/${RANDOM_ADDRESS}/txs`,
baseURL: 'node',
headers: sinon.match.any,
params: {
start: sinon.match.undefined,
},
}).resolves(TXS);

const wallet = new Wallet({
...defaultOptions,
});
await wallet.open({ data: RANDOM_SEED_PUB_KEY });
await wallet.load();

const res = await wallet.loadTransactions();
assert.equal(res.hasMore, true);
assert.equal(res.transactions.length, 5);
assert.equal(res.cursor, '4531732008A1841C46ABA924BCF1D467CB96F5FAAEAA7CACD2D7314723F13B96');
});
});
});

0 comments on commit 7575559

Please sign in to comment.