|
| 1 | +/* eslint-disable @typescript-eslint/no-floating-promises */ |
| 2 | +import { UpgradeabilityLibraryV1Instance } from '../../../types/truffle-contracts' |
| 3 | +import { deployProxy } from '../../test-lib/instance' |
| 4 | +import { getEventValue } from '../../test-lib/utils/event' |
| 5 | + |
| 6 | +contract('UpgradeabilityLibrary ', ([deployer, address, user]) => { |
| 7 | + describe('Same data', () => { |
| 8 | + let contract: UpgradeabilityLibraryV1Instance |
| 9 | + |
| 10 | + before(async () => { |
| 11 | + contract = await deployProxy( |
| 12 | + artifacts.require('UpgradeabilityLibraryV1'), |
| 13 | + deployer |
| 14 | + ) |
| 15 | + await contract.initialize() |
| 16 | + }) |
| 17 | + it('Store data', async () => { |
| 18 | + await Promise.all([ |
| 19 | + contract.setTestValue(5), |
| 20 | + contract.upCounter(), |
| 21 | + contract.addEnumerableSet(10), |
| 22 | + contract.addEnumerableSet(20), |
| 23 | + ]) |
| 24 | + |
| 25 | + expect((await contract.getCounter()).toString()).to.equal('1') |
| 26 | + const eSet = await contract.getEnumerableSet() |
| 27 | + expect(eSet.length).to.equal(2) |
| 28 | + const converted = eSet.map((v) => v.toNumber()) |
| 29 | + expect(converted.includes(10)).to.equal(true) |
| 30 | + expect(converted.includes(20)).to.equal(true) |
| 31 | + expect((await contract.testValue()).toString()).to.equal('5') |
| 32 | + }) |
| 33 | + it('Should data be upgradable', async () => { |
| 34 | + const newImpl = await artifacts.require('UpgradeabilityLibraryV2').new() |
| 35 | + contract.upgradeTo(newImpl.address) |
| 36 | + const [implementation] = await Promise.all([ |
| 37 | + getEventValue(contract)('Upgraded', 'implementation'), |
| 38 | + ]) |
| 39 | + expect(implementation).to.equal(newImpl.address) |
| 40 | + expect((await contract.getCounter()).toString()).to.equal('1') |
| 41 | + const eSet = await contract.getEnumerableSet() |
| 42 | + expect(eSet.length).to.equal(2) |
| 43 | + const converted = eSet.map((v) => v.toNumber()) |
| 44 | + expect(converted.includes(10)).to.equal(true) |
| 45 | + expect(converted.includes(20)).to.equal(true) |
| 46 | + expect((await contract.testValue()).toString()).to.equal('5') |
| 47 | + }) |
| 48 | + }) |
| 49 | +}) |
0 commit comments