Skip to content

Commit

Permalink
Adjust integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MiksuJak committed May 23, 2024
1 parent ab8f5d1 commit 2a56613
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion test/integration/governance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ describe('Governance', () => {
'stkTRU',
'guardian',
'proposalCount',
], '0xf6E2Da7D82ee49f76CE652bc0BeB546Cbe0Ea521')
], undefined, '0xf6E2Da7D82ee49f76CE652bc0BeB546Cbe0Ea521')
})
})
22 changes: 12 additions & 10 deletions test/integration/suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,23 @@ const execGetter = <T extends Contract>(contract: T) => async (getter: Getter<T>
export const TEST_STATE_BLOCK_NUMBER = 12010725

export function upgradeSuite<T extends Contract>(blockNumber: number, Factory: ContractFactoryConstructor<T>, currentAddress: string,
getters: Getter<T>[], contractsOwner?: string): Promise<T>
getters: Getter<T>[], newGetters?: Getter<T>[] | undefined, contractsOwner?: string): Promise<T>
export function upgradeSuite<T extends Contract>(Factory: ContractFactoryConstructor<T>, currentAddress: string,
getters: Getter<T>[], contractsOwner?: string): Promise<T>
getters: Getter<T>[], newGetters?: Getter<T>[] | undefined, contractsOwner?: string): Promise<T>
export function upgradeSuite (...args: any[]): any {
if (typeof args[0] === 'number') {
const [bn, factory, address, getters, owner] = args
return _upgradeSuite(factory, address, getters, owner, bn)
const [bn, factory, address, getters, newGetters, owner] = args
return _upgradeSuite(factory, address, getters, newGetters, owner, bn)
}
const [factory, address, getters, owner] = args
return _upgradeSuite(factory, address, getters, owner)
const [factory, address, getters, newGetters, owner] = args
return _upgradeSuite(factory, address, getters, newGetters, owner)
}

async function _upgradeSuite<T extends Contract> (
Factory: ContractFactoryConstructor<T>,
currentAddress: string,
getters: Getter<T>[],
newGetters: Getter<T>[] | undefined,
contractsOwner: string = CONTRACTS_OWNER,
blockNumber?: number | undefined,
) {
Expand All @@ -65,12 +66,13 @@ async function _upgradeSuite<T extends Contract> (
const oldValues = await Promise.all(getters.map(execGetter(existingContract)))
const proxy = new OwnedUpgradeabilityProxy__factory(owner).attach(currentAddress)
await (await proxy.upgradeTo(newContract.address)).wait()
const newValues = await Promise.all(getters.map(execGetter(existingContract)))
const postUpgradeGetters = newGetters || getters
const newValues = await Promise.all(postUpgradeGetters.map(execGetter(existingContract)))
for (let i = 0; i < oldValues.length; i++) {
expect(oldValues[i], `Possible corrupted storage:
Getter: ${getters[i]}
Current: ${oldValues[i].toString()}
Post upgrade: ${newValues[i].toString()} \n`).to.deep.equal(newValues[i])
Getter: ${getters[i]}
Current: ${oldValues[i].toString()}
Post upgrade: ${newValues[i].toString()} \n`).to.deep.equal(newValues[i])
}
return existingContract
}
9 changes: 9 additions & 0 deletions test/integration/truefi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,16 @@ describe('TrueFi', () => {
})

it('LinearDistributor', async () => {
// @ts-ignore
await upgradeSuite(TEST_STATE_BLOCK_NUMBER, LinearTrueDistributor__factory, '0xfB8d918428373f766B352564b70d1DcC1e3b6383', [
'trustToken',
'distributionStart',
'duration',
'totalAmount',
'lastDistribution',
'distributed',
'farm',
], [
'asset',
'distributionStart',
'duration',
Expand Down

0 comments on commit 2a56613

Please sign in to comment.