Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MEX-353] fix outdated contracts for users with no energy #1154

Merged
merged 2 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@
this.energyAbi.energyEntryForUser(userAddress),
]);

if (currentClaimProgress.week === 0) {
return new OutdatedContract();

Check warning on line 112 in src/modules/user/services/userEnergy/user.energy.compute.service.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/user/services/userEnergy/user.energy.compute.service.ts#L112

Added line #L112 was not covered by tests
}

const outdatedClaimProgress = currentClaimProgress.week !== currentWeek;

if (
Expand Down Expand Up @@ -137,6 +141,10 @@
this.energyAbi.energyEntryForUser(userAddress),
]);

if (currentClaimProgress.week === 0) {
return new OutdatedContract();
}

const outdatedClaimProgress = currentClaimProgress.week !== currentWeek;

if (
Expand Down
38 changes: 38 additions & 0 deletions src/modules/user/specs/user.energy.compute.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,42 @@ describe('UserEnergyComputeService', () => {
});
});

it('should NOT get outdated contracts if no claim progress', async () => {
const service = module.get<UserEnergyComputeService>(
UserEnergyComputeService,
);
const weeklyRewardsSplittingAbi =
module.get<WeeklyRewardsSplittingAbiService>(
WeeklyRewardsSplittingAbiService,
);
const weekTimekeepingAbi = module.get<WeekTimekeepingAbiService>(
WeekTimekeepingAbiService,
);
const energyAbi = module.get<EnergyAbiService>(EnergyAbiService);
jest.spyOn(
weeklyRewardsSplittingAbi,
'currentClaimProgress',
).mockResolvedValue({
week: 0,
energy: {
amount: '0',
lastUpdateEpoch: 0,
totalLockedTokens: '0',
},
});
jest.spyOn(weekTimekeepingAbi, 'currentWeek').mockResolvedValue(10);
jest.spyOn(energyAbi, 'energyEntryForUser').mockResolvedValue({
amount: '0',
lastUpdateEpoch: 0,
totalLockedTokens: '0',
});

const outdatedContracts =
await service.computeFeesCollectorOutdatedContract(
Address.Zero().bech32(),
);

expect(outdatedContracts).toEqual({});
});

});
Loading