@dydxfoundation/governance
Version:
dYdX governance smart contracts
75 lines (74 loc) • 4.37 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/* eslint-disable @typescript-eslint/brace-style */
const bignumber_js_1 = __importDefault(require("bignumber.js"));
const chai_1 = require("chai");
const lodash_1 = __importDefault(require("lodash"));
const affected_stakers_1 = require("../../src/lib/affected-stakers");
const impersonate_account_1 = require("../../src/migrations/helpers/impersonate-account");
const describe_contract_1 = require("../helpers/describe-contract");
const get_affected_stakers_for_test_1 = require("../helpers/get-affected-stakers-for-test");
const EXPECTED_TOTAL_OWED = '173204761823871505252385';
let testStakers;
let testAllStakers;
let contract;
function init(ctx) {
testStakers = (0, get_affected_stakers_for_test_1.getAffectedStakersForTest)();
testAllStakers = testStakers.length == affected_stakers_1.AFFECTED_STAKERS.length;
contract = ctx.safetyModuleRecovery;
}
(0, describe_contract_1.describeContractHardhatRevertBeforeEach)('SM2Recovery', init, (ctx) => {
it('Proxy admin is owned by the short timelock', async () => {
const owner = await ctx.safetyModuleRecoveryProxyAdmin.owner();
(0, chai_1.expect)(owner).to.equal(ctx.shortTimelock.address);
});
it('Receives tokens from the Safety Module', async () => {
// Get the totals for the subset of addresses being tested.
const balance = await ctx.dydxToken.balanceOf(contract.address);
(0, chai_1.expect)(balance).to.equal(EXPECTED_TOTAL_OWED);
// Verify the contract balance in the “full test” case with all stakers.
if (testAllStakers) {
const testTotalOwed = lodash_1.default.reduce(testStakers, (accOwed, stakerAddress) => {
return accOwed.plus((0, affected_stakers_1.getOwedAmount)(stakerAddress));
}, new bignumber_js_1.default(0));
(0, chai_1.expect)(balance).to.equal(testTotalOwed.toFixed());
}
});
it('Affected stakers can claim the owed amount', async () => {
for (const stakerAddress of testStakers) {
// Fund account if needed. This is useful e.g. when using mainnet forking.
if ((await ctx.dydxToken.balanceOf(stakerAddress)).lt(impersonate_account_1.IMPERSONATED_ACCOUNT_STIPEND)) {
await (0, impersonate_account_1.fundAccount)(stakerAddress);
}
const expectedOwedAmount = (0, affected_stakers_1.getOwedAmount)(stakerAddress);
// Note: Assume that the staker was already funded with ETH during deployment.
const staker = await (0, impersonate_account_1.impersonateAccount)(stakerAddress);
const contractAsStaker = contract.connect(staker);
const contractOwedAmount = await contract.getOwedAmount(stakerAddress);
const claimableAmount = await contractAsStaker.callStatic.claim();
(0, chai_1.expect)(contractOwedAmount).to.equal(expectedOwedAmount);
(0, chai_1.expect)(claimableAmount).to.equal(expectedOwedAmount);
// Claim the owed amount.
const balanceBefore = await ctx.dydxToken.balanceOf(stakerAddress);
await contractAsStaker.claim();
const balanceAfter = await ctx.dydxToken.balanceOf(stakerAddress);
(0, chai_1.expect)(balanceAfter).to.equal(balanceBefore.add(expectedOwedAmount));
const contractOwedAmountAfter = await contract.getOwedAmount(stakerAddress);
(0, chai_1.expect)(contractOwedAmountAfter).to.equal(0);
const claimableAmountAfter = await contractAsStaker.callStatic.claim();
(0, chai_1.expect)(claimableAmountAfter).to.equal(0);
}
// Verify the contract balance in the “full test” case with all stakers.
if (testAllStakers) {
const endingContractBalance = await ctx.dydxToken.balanceOf(contract.address);
(0, chai_1.expect)(endingContractBalance).to.equal(0);
}
});
it('Tested with at least three test stakers', () => {
// Fail on hardhat network if the configured numTestStakers is too low.
(0, chai_1.expect)(testStakers.length).to.be.greaterThanOrEqual(3);
});
});