Skip to content

Commit

Permalink
test: add test case for ma account balance transition
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan Cruz committed Jan 18, 2021
1 parent ed607fd commit 3a81809
Show file tree
Hide file tree
Showing 2 changed files with 273 additions and 7 deletions.
68 changes: 63 additions & 5 deletions cardano-rosetta-server/test/e2e/account/account-api.test.ts
Expand Up @@ -4,7 +4,15 @@ import { FastifyInstance } from 'fastify';
import StatusCodes from 'http-status-codes';
import { Pool } from 'pg';
import { CARDANO } from '../../../src/server/utils/constants';
import { latestBlockIdentifier, vpfHashAccountBalances, vpfHashCoins } from '../fixture-data';
import {
latestBlockIdentifier,
address1vpfAccountBalances,
address1vpfCoins,
balancesAtBlock213891,
balancesAtBlock213892,
coinsAtBlock213891,
coinsAtBlock213892
} from '../fixture-data';
import { setupDatabase, setupServer } from '../utils/test-utils';

const generatePayload = (
Expand Down Expand Up @@ -435,9 +443,59 @@ describe('/account/balance endpoint', () => {
index: 347898,
hash: '1f391a9c0d5799e96aae4df2b22c361346bc98d3e46a2c3496632fdcae52f65b'
});
expect(response.json().balances.length).toEqual(vpfHashAccountBalances.length);
vpfHashAccountBalances.forEach(accountBalance => expect(response.json().balances).toContainEqual(accountBalance));
expect(response.json().coins.length).toEqual(vpfHashCoins.length);
vpfHashCoins.forEach(vpfHashCoin => expect(response.json().coins).toContainEqual(vpfHashCoin));
expect(response.json().balances.length).toEqual(address1vpfAccountBalances.length);
address1vpfAccountBalances.forEach(accountBalance =>
expect(response.json().balances).toContainEqual(accountBalance)
);
expect(response.json().coins.length).toEqual(address1vpfCoins.length);
address1vpfCoins.forEach(address1vpfCoin => expect(response.json().coins).toContainEqual(address1vpfCoin));
});
// eslint-disable-next-line max-len
test('given a block with ma balances and the total amount of one of them are transferred in the current block, that token balance should not be seen at the address balance for the next block', async () => {
const responseAtBlock213891 = await serverWithMultiassetsSupport.inject({
method: 'post',
url: ACCOUNT_BALANCE_ENDPOINT,
payload: generatePayload(
CARDANO,
'mainnet',
'addr_test1vpfwv0ezc5g8a4mkku8hhy3y3vp92t7s3ul8g778g5yegsgalc6gc',
213891,
'ee0c724096119dd8a1feda1c528ca3c3e54b875bbdc67def25b6a244dab43099'
)
});
const responseAtBlock213892 = await serverWithMultiassetsSupport.inject({
method: 'post',
url: ACCOUNT_BALANCE_ENDPOINT,
payload: generatePayload(
CARDANO,
'mainnet',
'addr_test1vpfwv0ezc5g8a4mkku8hhy3y3vp92t7s3ul8g778g5yegsgalc6gc',
213892,
'f2a86b45724e1d6e37796abca3dce176ba817537b7f15a477bf4bd5927d24e1e'
)
});

expect(responseAtBlock213891.statusCode).toEqual(StatusCodes.OK);
expect(responseAtBlock213891.json().block_identifier).toEqual({
index: 213891,
hash: 'ee0c724096119dd8a1feda1c528ca3c3e54b875bbdc67def25b6a244dab43099'
});

expect(responseAtBlock213891.json().balances.length).toEqual(balancesAtBlock213891.length);
balancesAtBlock213891.forEach(accountBalance =>
expect(responseAtBlock213891.json().balances).toContainEqual(accountBalance)
);
expect(responseAtBlock213891.json().coins.length).toEqual(coinsAtBlock213891.length);
coinsAtBlock213891.forEach(coin => expect(responseAtBlock213891.json().coins).toContainEqual(coin));
expect(responseAtBlock213892.statusCode).toEqual(StatusCodes.OK);
expect(responseAtBlock213892.json().block_identifier).toEqual({
index: 213892,
hash: 'f2a86b45724e1d6e37796abca3dce176ba817537b7f15a477bf4bd5927d24e1e'
});
balancesAtBlock213892.forEach(accountBalance =>
expect(responseAtBlock213892.json().balances).toContainEqual(accountBalance)
);
expect(responseAtBlock213892.json().coins.length).toEqual(coinsAtBlock213892.length);
coinsAtBlock213892.forEach(coin => expect(responseAtBlock213892.json().coins).toContainEqual(coin));
});
});
212 changes: 210 additions & 2 deletions cardano-rosetta-server/test/e2e/fixture-data.ts
Expand Up @@ -2238,7 +2238,7 @@ export const CONSTRUCTION_COMBINE_PAYLOAD = {
]
};

export const vpfHashAccountBalances = [
export const address1vpfAccountBalances = [
{
value: '639308468',
currency: {
Expand Down Expand Up @@ -2369,7 +2369,7 @@ export const vpfHashAccountBalances = [
];

const coinId6c18 = { identifier: '6c181e6875eb4e24e9b05b26e2361790a4e5d65cd4d63d68cce40eb9098ce847:0' };
export const vpfHashCoins = [
export const address1vpfCoins = [
{
coin_identifier: coinId6c18,
amount: {
Expand Down Expand Up @@ -2640,3 +2640,211 @@ export const vpfHashCoins = [
}
}
];

export const balancesAtBlock213891 = [
{
value: '299994729944',
currency: {
decimals: 6,
symbol: 'ADA'
}
},
{
value: '10',
currency: {
decimals: 0,
symbol: 'testtoken',
metadata: {
policy: '06e5f0ade7121aaefa0e7ec53cac61820d774de0c12c83e8597627ff'
}
}
},
{
value: '95',
currency: {
decimals: 0,
symbol: 'ATADAcoin',
metadata: {
policy: '34250edd1e9836f5378702fbf9416b709bc140e04f668cc355208518'
}
}
},
{
value: '2500',
currency: {
decimals: 0,
symbol: 'machtlcoin',
metadata: {
policy: '34250edd1e9836f5378702fbf9416b709bc140e04f668cc355208518'
}
}
},
{
value: '500',
currency: {
decimals: 0,
symbol: 'machtl2coin',
metadata: {
policy: 'ecd07b4ef62f37a68d145de8efd60c53d288dd5ffc641215120cc3db'
}
}
}
];

const coinId30d9 = { identifier: '30d97e64d1892ed7e03faf544318f167443a0153c244305df9b0f796a0386c8b:0' };
export const coinsAtBlock213891 = [
{
coin_identifier: coinId30d9,
amount: {
value: '299994729944',
currency: {
decimals: 6,
symbol: 'ADA'
}
}
},
{
coin_identifier: coinId30d9,
amount: {
value: '10',
currency: {
decimals: 0,
symbol: 'testtoken',
metadata: {
policy: '06e5f0ade7121aaefa0e7ec53cac61820d774de0c12c83e8597627ff'
}
}
}
},
{
coin_identifier: coinId30d9,
amount: {
value: '95',
currency: {
decimals: 0,
symbol: 'ATADAcoin',
metadata: {
policy: '34250edd1e9836f5378702fbf9416b709bc140e04f668cc355208518'
}
}
}
},
{
coin_identifier: coinId30d9,
amount: {
value: '2500',
currency: {
decimals: 0,
symbol: 'machtlcoin',
metadata: {
policy: '34250edd1e9836f5378702fbf9416b709bc140e04f668cc355208518'
}
}
}
},
{
coin_identifier: coinId30d9,
amount: {
value: '500',
currency: {
decimals: 0,
symbol: 'machtl2coin',
metadata: {
policy: 'ecd07b4ef62f37a68d145de8efd60c53d288dd5ffc641215120cc3db'
}
}
}
}
];
export const balancesAtBlock213892 = [
{
value: '299994547239',
currency: {
decimals: 6,
symbol: 'ADA'
}
},
{
value: '95',
currency: {
decimals: 0,
symbol: 'ATADAcoin',
metadata: {
policy: '34250edd1e9836f5378702fbf9416b709bc140e04f668cc355208518'
}
}
},
{
value: '2500',
currency: {
decimals: 0,
symbol: 'machtlcoin',
metadata: {
policy: '34250edd1e9836f5378702fbf9416b709bc140e04f668cc355208518'
}
}
},
{
value: '500',
currency: {
decimals: 0,
symbol: 'machtl2coin',
metadata: {
policy: 'ecd07b4ef62f37a68d145de8efd60c53d288dd5ffc641215120cc3db'
}
}
}
];

const coinId1a04 = { identifier: '1a04005e5459b07a6353f5c1a9b1066d5969638b681923af6cb0601cf8c57495:0' };
export const coinsAtBlock213892 = [
{
coin_identifier: coinId1a04,
amount: {
value: '299994547239',
currency: {
decimals: 6,
symbol: 'ADA'
}
}
},
{
coin_identifier: coinId1a04,
amount: {
value: '500',
currency: {
decimals: 0,
symbol: 'machtl2coin',
metadata: {
policy: 'ecd07b4ef62f37a68d145de8efd60c53d288dd5ffc641215120cc3db'
}
}
}
},
{
coin_identifier: coinId1a04,
amount: {
value: '2500',
currency: {
decimals: 0,
symbol: 'machtlcoin',
metadata: {
policy: '34250edd1e9836f5378702fbf9416b709bc140e04f668cc355208518'
}
}
}
},
{
coin_identifier: coinId1a04,
amount: {
value: '95',
currency: {
decimals: 0,
symbol: 'ATADAcoin',
metadata: {
policy: '34250edd1e9836f5378702fbf9416b709bc140e04f668cc355208518'
}
}
}
}
];

0 comments on commit 3a81809

Please sign in to comment.