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 claim progress #1147

Merged
merged 2 commits into from
Aug 18, 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 @@ -2,7 +2,12 @@
import { scAddress } from '../../../../config';
import { EnergyType } from '@multiversx/sdk-exchange';
import { ClaimProgress } from '../../../../submodules/weekly-rewards-splitting/models/weekly-rewards-splitting.model';
import { ContractType, OutdatedContract, UserDualYiledToken, UserLockedFarmTokenV2 } from '../../models/user.model';
import {
ContractType,
OutdatedContract,
UserDualYiledToken,
UserLockedFarmTokenV2,
} from '../../models/user.model';
import { UserMetaEsdtService } from '../user.metaEsdt.service';
import { PaginationArgs } from '../../../dex.model';
import { ProxyService } from '../../../proxy/services/proxy.service';
Expand All @@ -11,9 +16,7 @@
import { farmVersion } from '../../../../utils/farm.utils';
import { BigNumber } from 'bignumber.js';
import { WeekTimekeepingAbiService } from 'src/submodules/week-timekeeping/services/week-timekeeping.abi.service';
import {
WeeklyRewardsSplittingAbiService,
} from 'src/submodules/weekly-rewards-splitting/services/weekly-rewards-splitting.abi.service';
import { WeeklyRewardsSplittingAbiService } from 'src/submodules/weekly-rewards-splitting/services/weekly-rewards-splitting.abi.service';
import { StakingProxyAbiService } from 'src/modules/staking-proxy/services/staking.proxy.abi.service';
import { FarmAbiFactory } from 'src/modules/farm/farm.abi.factory';
import { FarmFactoryService } from 'src/modules/farm/farm.factory';
Expand Down Expand Up @@ -105,12 +108,16 @@
this.energyAbi.energyEntryForUser(userAddress),
]);

if (this.isEnergyOutdated(userEnergy, currentClaimProgress)) {
const outdatedClaimProgress = currentClaimProgress.week !== currentWeek;

Check warning on line 111 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#L111

Added line #L111 was not covered by tests

if (
this.isEnergyOutdated(userEnergy, currentClaimProgress) ||
outdatedClaimProgress
) {
return new OutdatedContract({
address: contractAddress,
type: ContractType.Farm,
claimProgressOutdated:
currentClaimProgress.week !== currentWeek,
claimProgressOutdated: outdatedClaimProgress,
farmToken: farmToken.collection,
});
}
Expand All @@ -130,11 +137,16 @@
this.energyAbi.energyEntryForUser(userAddress),
]);

if (this.isEnergyOutdated(userEnergy, currentClaimProgress)) {
const outdatedClaimProgress = currentClaimProgress.week !== currentWeek;

if (
this.isEnergyOutdated(userEnergy, currentClaimProgress) ||
outdatedClaimProgress
) {
return new OutdatedContract({
address: scAddress.feesCollector,
type: ContractType.FeesCollector,
claimProgressOutdated: currentClaimProgress.week != currentWeek,
claimProgressOutdated: outdatedClaimProgress,
});
}
return new OutdatedContract();
Expand Down
47 changes: 47 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 @@ -68,6 +68,12 @@ import { StakingProxyService } from '../../staking-proxy/services/staking.proxy.
import { StakingProxyAbiService } from '../../staking-proxy/services/staking.proxy.abi.service';
import { UserEnergyComputeService } from '../services/userEnergy/user.energy.compute.service';
import { MXProxyServiceProvider } from '../../../services/multiversx-communication/mx.proxy.service.mock';
import { Address } from '@multiversx/sdk-core/out';
import { scAddress } from 'src/config';
import { ContractType } from '../models/user.model';
import { WeeklyRewardsSplittingAbiService } from 'src/submodules/weekly-rewards-splitting/services/weekly-rewards-splitting.abi.service';
import { WeekTimekeepingAbiService } from 'src/submodules/week-timekeeping/services/week-timekeeping.abi.service';
import { EnergyAbiService } from 'src/modules/energy/services/energy.abi.service';

describe('UserEnergyComputeService', () => {
let module: TestingModule;
Expand Down Expand Up @@ -195,5 +201,46 @@ describe('UserEnergyComputeService', () => {
})).toBe(false);
});

it('should get outdated contracts on old 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: 9,
energy: {
amount: '105',
lastUpdateEpoch: 9,
totalLockedTokens: '5',
},
});
jest.spyOn(weekTimekeepingAbi, 'currentWeek').mockResolvedValue(10);
jest.spyOn(energyAbi, 'energyEntryForUser').mockResolvedValue({
amount: '100',
lastUpdateEpoch: 10,
totalLockedTokens: '5',
});

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

expect(outdatedContracts).toEqual({
address: scAddress.feesCollector,
type: ContractType.FeesCollector,
claimProgressOutdated: true,
});
});

});
Loading