Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ianhe8x committed Apr 23, 2024
1 parent 8978394 commit 8fe0cf8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
6 changes: 3 additions & 3 deletions contracts/Staking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,14 @@ contract Staking is IStaking, Initializable, OwnableUpgradeable {
'G008'
);
require(_amount > 0, 'S003');

reflectEraUpdate(_source, _runner);

if (this.isEmptyDelegation(_source, _runner)) {
stakingIndexerNos[_source][_runner] = stakingIndexerLengths[_source];
stakingIndexers[_source][stakingIndexerLengths[_source]] = _runner;
stakingIndexerLengths[_source]++;
}

reflectEraUpdate(_source, _runner);

// first stake from runner
bool firstStake = this.isEmptyDelegation(_runner, _runner) &&
totalStakingAmount[_runner].valueAt == 0 &&
Expand Down
2 changes: 1 addition & 1 deletion test/Maintenance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('Maintenance Mode Test', () => {
await token.connect(wallet_2).increaseAllowance(staking.address, etherParse('10000'));
await token.increaseAllowance(staking.address, etherParse('10000'));
await token.increaseAllowance(purchaseOfferMarket.address, etherParse('10000'));
await indexerRegistry.registerIndexer(etherParse('1000'), METADATA_HASH, 0);
await indexerRegistry.registerIndexer(etherParse('1001'), METADATA_HASH, 0);
await indexerRegistry.connect(wallet_2).registerIndexer(etherParse('1000'), METADATA_HASH, 0);

await planManager.createPlanTemplate(time.duration.days(3).toString(), 1000, 100, token.address, METADATA_HASH);
Expand Down
7 changes: 5 additions & 2 deletions test/RewardsDistributer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,12 +584,13 @@ describe('RewardsDistributor Contract', () => {
await stakingManager.connect(delegator).undelegate(runner.address, etherParse('1'));
// 3. start new era -> delegator -> `applyStakeChange`
await startNewEra(eraManager);
await rewardsHelper.indexerCatchup(runner.address);
await rewardsHelper.connect(runner).indexerCatchup(runner.address);
// 4. check totalStakingAmount equal 0, era reward equal 0
await checkValues(etherParse('2.697302697'), etherParse('9.002697302697'), 0, 0);
// 5. indexer register successfully
await stakingManager.connect(runner).widthdraw();
await token.connect(runner).increaseAllowance(staking.address, etherParse('1000'));
await staking.reflectEraUpdate(runner.address, runner.address);
await indexerRegistry
.connect(runner)
.registerIndexer(etherParse('1000'), METADATA_HASH, 100, { gasLimit: '2000000' });
Expand All @@ -604,6 +605,7 @@ describe('RewardsDistributor Contract', () => {
await stakingManager.connect(runner).widthdraw();
await stakingManager.connect(delegator).widthdraw();
// 3. indexer reregister -> add previous delegator and a new delegator
await staking.reflectEraUpdate(runner.address, runner.address);
await token.connect(runner).increaseAllowance(staking.address, etherParse('1000'));
await indexerRegistry
.connect(runner)
Expand Down Expand Up @@ -633,7 +635,7 @@ describe('RewardsDistributor Contract', () => {
await checkValues(etherParse('4.996702697'), etherParse('9.001697302697'), etherParse('1002'), 0);
});

it('reward distribution should work after indexer reregister few more ears later', async () => {
it.only('reward distribution should work after indexer reregister few more ears later', async () => {
// 1. delegator undelegate all the tokens
await stakingManager.connect(delegator).undelegate(runner.address, etherParse('1'));
// 2. start new era -> indexer `collectAndDistributeRewards` -> `applyStakeChange | delegator -> `applyStakeChange`
Expand All @@ -645,6 +647,7 @@ describe('RewardsDistributor Contract', () => {
await startNewEra(eraManager);
await startNewEra(eraManager);
// 3. indexer reregister -> add previous delegator and a new delegator
await staking.reflectEraUpdate(runner.address, runner.address);
await token.connect(runner).increaseAllowance(staking.address, etherParse('1000'));
await indexerRegistry
.connect(runner)
Expand Down
2 changes: 1 addition & 1 deletion test/Staking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ describe('Staking Contract', () => {
});

it('request unregister to unstaking all by indexer registry should work', async () => {
await indexerRegistry.unregisterIndexer({ gasLimit: '1000000' });
await indexerRegistry.connect(runner).unregisterIndexer({ gasLimit: '1000000' });

// check changes of indexer storage
await startNewEra(eraManager);
Expand Down

0 comments on commit 8fe0cf8

Please sign in to comment.