Skip to content

Commit

Permalink
test: add test for frozen deprecation in runtime (#1353)
Browse files Browse the repository at this point in the history
  • Loading branch information
TarikGul authored Nov 16, 2023
1 parent bdb9271 commit 1a249a3
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
58 changes: 57 additions & 1 deletion src/services/accounts/AccountsBalanceInfoService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ import { ApiDecoration } from '@polkadot/api/types';
import { AccountInfo, Address, Hash } from '@polkadot/types/interfaces';

import { sanitizeNumbers } from '../../sanitize/sanitizeNumbers';
import { polkadotRegistry } from '../../test-helpers/registries';
import {
polkadotRegistry,
polkadotRegistryV9370,
} from '../../test-helpers/registries';
import {
blockHash789629,
defaultMockApi,
testAddress,
} from '../test-helpers/mock';
import accountsBalanceInfo789629 from '../test-helpers/responses/accounts/balanceInfo789629.json';
import accountsBalanceInfoFeeFrozen from '../test-helpers/responses/accounts/balanceInfoFeeFrozen.json';
import { AccountsBalanceInfoService } from './AccountsBalanceInfoService';

const locksAt = (_address: string) =>
Expand All @@ -48,6 +52,19 @@ const accountAt = (_address: string) =>
)
);

const accountDataAt = (_address: String) =>
Promise.resolve().then(() => {
return {
data: polkadotRegistryV9370.createType('AccountData', {
free: '100000',
reserved: '100000',
miscFrozen: '111111',
feeFrozen: '111111',
}),
nonce: polkadotRegistry.createType('Index', 1),
};
});

const freeBalanceAt = () =>
Promise.resolve().then(() =>
polkadotRegistry.createType('Balance', 123456789)
Expand Down Expand Up @@ -103,6 +120,45 @@ describe('AccountsBalanceInfoService', () => {
).toStrictEqual(accountsBalanceInfo789629);
});

it('works when the api does not have the frozen field in Account data', async () => {
const tmpHistoricApi = {
registry: polkadotRegistry,
query: {
balances: {
freeBalance: undefined,
reservedBalance: async () =>
polkadotRegistry.createType('Balance', 1),
locks: locksAt,
},
system: {
accountNonce: async () => polkadotRegistry.createType('Index', 1),
account: accountDataAt,
},
},
} as unknown as ApiDecoration<'promise'>;

const tmpMockApi = {
...defaultMockApi,
at: (_hash: Hash) => tmpHistoricApi,
} as unknown as ApiPromise;

const tmpAccountsBalanceInfoService = new AccountsBalanceInfoService(
tmpMockApi
);

expect(
sanitizeNumbers(
await tmpAccountsBalanceInfoService.fetchAccountBalanceInfo(
blockHash789629,
tmpHistoricApi,
testAddress,
'DOT',
false
)
)
).toStrictEqual(accountsBalanceInfoFeeFrozen);
});

it('Correctly queries historical blocks', async () => {
const result = await accountsBalanceInfoService.fetchAccountBalanceInfo(
blockHash789629,
Expand Down
2 changes: 1 addition & 1 deletion src/services/accounts/AccountsBalanceInfoService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class AccountsBalanceInfoService extends AbstractService {
const { data, nonce } = accountInfo;

let free, reserved, feeFrozen, miscFrozen, frozen;
if (accountInfo.data.frozen) {
if (accountInfo.data?.frozen) {
free = data.free;
reserved = data.reserved;
frozen = data.frozen;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"at": {
"hash": "0x7b713de604a99857f6c25eacc115a4f28d2611a23d9ddff99ab0e4f1c17a8578",
"height": "789629"
},
"nonce": "1",
"tokenSymbol": "DOT",
"free": "100000",
"reserved": "100000",
"miscFrozen": "111111",
"feeFrozen": "111111",
"frozen": "frozen does not exist for this runtime",
"locks": [
{
"id": "0x7374616b696e6720",
"amount": "100000000000",
"reasons": "All"
}
]
}

0 comments on commit 1a249a3

Please sign in to comment.