Skip to content

Commit

Permalink
test: improve snapshot consistency for rewards and network info
Browse files Browse the repository at this point in the history
  • Loading branch information
lgobbi-atix committed Jun 27, 2022
1 parent 7489073 commit 0b2063a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 99 deletions.
Expand Up @@ -185,7 +185,12 @@ describe('NetworkInfoHttpService', () => {

it('response is an object of network info', async () => {
const response = await provider.networkInfo();
expect(response).toMatchSnapshot();
expect(response.lovelaceSupply.total).toBeGreaterThan(0);
expect(response.lovelaceSupply.circulating).toBeGreaterThan(0);
expect(response.lovelaceSupply.max).toBeGreaterThan(response.lovelaceSupply.total);
expect(response.stake.active).toBeGreaterThan(0);
expect(response.stake.live).toBeGreaterThan(0);
expect(response.network).toMatchSnapshot();
});

it('response is an object of ledger tip', async () => {
Expand Down
Expand Up @@ -44,32 +44,21 @@ Object {

exports[`NetworkInfoHttpService healthy state with NetworkInfoHttpProvider response is an object of network info 1`] = `
Object {
"lovelaceSupply": Object {
"circulating": 69173735562813828n,
"max": 45000000000000000n,
"total": 40342337171803411n,
},
"network": Object {
"id": 0,
"magic": 1097911063,
"timeSettings": Array [
Object {
"epochLength": 21600,
"fromSlotDate": 2019-07-24T20:20:16.000Z,
"fromSlotNo": 0,
"slotLength": 20000,
},
Object {
"epochLength": 432000,
"fromSlotDate": 2020-07-28T19:20:16.000Z,
"fromSlotNo": 1598400,
"slotLength": 1000,
},
],
},
"stake": Object {
"active": 14977960053990832n,
"live": 69154425288708824n,
},
"id": 0,
"magic": 1097911063,
"timeSettings": Array [
Object {
"epochLength": 21600,
"fromSlotDate": 2019-07-24T20:20:16.000Z,
"fromSlotNo": 0,
"slotLength": 20000,
},
Object {
"epochLength": 432000,
"fromSlotDate": 2020-07-28T19:20:16.000Z,
"fromSlotNo": 1598400,
"slotLength": 1000,
},
],
}
`;
Expand Up @@ -29,33 +29,32 @@ describe('RewardsBuilder', () => {
describe('getRewardsHistory', () => {
it('returns RewardEpochModel when there is no epochs field', async () => {
const result = await builder.getRewardsHistory([rewardAccWithBalance]);
expect(result).toMatchSnapshot();
expect(result.length).toBeGreaterThan(0);
});
it('returns RewardEpochModel when there is no epochs field and empty accounts', async () => {
const result = await builder.getRewardsHistory([]);
expect(result).toMatchSnapshot();
expect(result).toHaveLength(0);
});
it('returns RewardEpochModel when there is epochs field', async () => {
const epochs = {
lowerBound: 10,
upperBound: 20
};
const epochs = { lowerBound: 80, upperBound: 90 };
const result = await builder.getRewardsHistory([rewardAccWithBalance], epochs);
expect(result).toMatchSnapshot();
expect(result).toHaveLength(2);
for (const reward of result) {
expect(Number(reward.epoch)).toBeGreaterThanOrEqual(epochs.lowerBound);
expect(Number(reward.epoch)).toBeLessThanOrEqual(epochs.upperBound);
}
});
it('returns RewardEpochModel when there is partially epochs field with lowerBound', async () => {
const epochs = {
lowerBound: 10
};
const epochs = { lowerBound: 10 };
const result = await builder.getRewardsHistory([rewardAccWithBalance], epochs);
expect(result).toMatchSnapshot();
expect(result.length).toBeGreaterThan(0);
for (const reward of result) expect(Number(reward.epoch)).toBeGreaterThanOrEqual(epochs.lowerBound);
});
it('returns RewardEpochModel when there is partially epochs field with upperBound', async () => {
const epochs = {
upperBound: 20
};
const epochs = { upperBound: 90 };
const result = await builder.getRewardsHistory([rewardAccWithBalance], epochs);
expect(result).toMatchSnapshot();
expect(result).toHaveLength(2);
for (const reward of result) expect(Number(reward.epoch)).toBeLessThanOrEqual(epochs.upperBound);
});
});
});
Expand Up @@ -11,59 +11,3 @@ Object {
"balance": "97675046319",
}
`;

exports[`RewardsBuilder getRewardsHistory returns RewardEpochModel when there is epochs field 1`] = `Array []`;

exports[`RewardsBuilder getRewardsHistory returns RewardEpochModel when there is no epochs field 1`] = `
Array [
Object {
"address": "stake_test1uqfu74w3wh4gfzu8m6e7j987h4lq9r3t7ef5gaw497uu85qsqfy27",
"epoch": "169",
"quantity": "9225614904",
},
Object {
"address": "stake_test1uqfu74w3wh4gfzu8m6e7j987h4lq9r3t7ef5gaw497uu85qsqfy27",
"epoch": "88",
"quantity": "10994270921",
},
Object {
"address": "stake_test1uqfu74w3wh4gfzu8m6e7j987h4lq9r3t7ef5gaw497uu85qsqfy27",
"epoch": "85",
"quantity": "12597745314",
},
Object {
"address": "stake_test1uqfu74w3wh4gfzu8m6e7j987h4lq9r3t7ef5gaw497uu85qsqfy27",
"epoch": "161",
"quantity": "16214946715",
},
]
`;

exports[`RewardsBuilder getRewardsHistory returns RewardEpochModel when there is no epochs field and empty accounts 1`] = `Array []`;

exports[`RewardsBuilder getRewardsHistory returns RewardEpochModel when there is partially epochs field with lowerBound 1`] = `
Array [
Object {
"address": "stake_test1uqfu74w3wh4gfzu8m6e7j987h4lq9r3t7ef5gaw497uu85qsqfy27",
"epoch": "169",
"quantity": "9225614904",
},
Object {
"address": "stake_test1uqfu74w3wh4gfzu8m6e7j987h4lq9r3t7ef5gaw497uu85qsqfy27",
"epoch": "88",
"quantity": "10994270921",
},
Object {
"address": "stake_test1uqfu74w3wh4gfzu8m6e7j987h4lq9r3t7ef5gaw497uu85qsqfy27",
"epoch": "85",
"quantity": "12597745314",
},
Object {
"address": "stake_test1uqfu74w3wh4gfzu8m6e7j987h4lq9r3t7ef5gaw497uu85qsqfy27",
"epoch": "161",
"quantity": "16214946715",
},
]
`;

exports[`RewardsBuilder getRewardsHistory returns RewardEpochModel when there is partially epochs field with upperBound 1`] = `Array []`;

0 comments on commit 0b2063a

Please sign in to comment.