Skip to content

Commit a3e4142

Browse files
fariedtzone117x
authored andcommitted
chore: add test to ensure fees are calculated properly
- pick an account that makes a transaction in an earlier test - check its balance in a block before it makes a transaction - make sure the balance in that block is 0.
1 parent 5c36111 commit a3e4142

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

src/tests-rosetta/api.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,56 @@ describe('Rosetta API', () => {
600600
expect(JSON.parse(result1.text)).toEqual(expectedResponse);
601601
});
602602

603+
test('account/balance - fees calculated properly', async () => {
604+
// this account has made one transaction
605+
// ensure that the fees for it are calculated after it makes
606+
// the transaction, not before, by checking its balance in block 1
607+
const stxAddress = 'ST1HB1T8WRNBYB0Y3T7WXZS38NKKPTBR3EG9EPJKR';
608+
const request1: RosettaAccountBalanceRequest = {
609+
network_identifier: {
610+
blockchain: 'stacks',
611+
network: 'testnet',
612+
},
613+
block_identifier: {
614+
index: 1,
615+
},
616+
account_identifier: {
617+
address: stxAddress,
618+
},
619+
};
620+
621+
const result1 = await supertest(api.server).post(`/rosetta/v1/account/balance/`).send(request1);
622+
console.log('account balance', result1.text);
623+
expect(result1.status).toBe(200);
624+
expect(result1.type).toBe('application/json');
625+
626+
const block = await api.datastore.getBlockByHeight(1);
627+
assert(block.found);
628+
629+
const amount: RosettaAmount = {
630+
value: '0',
631+
currency: {
632+
symbol: 'STX',
633+
decimals: 6,
634+
},
635+
};
636+
637+
const expectedResponse: RosettaAccountBalanceResponse = {
638+
block_identifier: {
639+
hash: block.result.block_hash,
640+
index: block.result.block_height,
641+
},
642+
balances: [amount],
643+
644+
coins: [],
645+
metadata: {
646+
sequence_number: 0,
647+
},
648+
};
649+
650+
expect(JSON.parse(result1.text)).toEqual(expectedResponse);
651+
});
652+
603653
test('account/balance - invalid account identifier', async () => {
604654
const request: RosettaAccountBalanceRequest = {
605655
network_identifier: {

0 commit comments

Comments
 (0)