Skip to content

Commit

Permalink
test(its-factory): add upgrade test (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
milapsheth authored Nov 17, 2024
1 parent 7e6916d commit c1e80a9
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/codecov.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ jobs:
run: npm run coverage

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: lcov.info
files: coverage/lcov.info
fail_ci_if_error: true
10 changes: 10 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
coverage:
status:
project:
default:
target: auto
threshold: 0%
patch:
default:
target: auto
threshold: 0%
2 changes: 1 addition & 1 deletion contracts/InterchainTokenFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ contract InterchainTokenFactory is IInterchainTokenFactory, ITokenManagerType, M
chainNameHash = interchainTokenService.chainNameHash();
}

function _setup(bytes calldata data) internal override {}
function _setup(bytes calldata /* data */) internal pure override {}

/**
* @notice Getter for the contract id.
Expand Down
37 changes: 36 additions & 1 deletion test/InterchainTokenFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { ethers } = require('hardhat');
const {
getContractAt,
Wallet,
constants: { AddressZero },
constants: { AddressZero, HashZero },
utils: { defaultAbiCoder, keccak256, toUtf8Bytes, arrayify },
} = ethers;
const { deployAll, deployContract } = require('../scripts/deploy');
Expand All @@ -19,6 +19,7 @@ const {
OPERATOR_ROLE,
FLOW_LIMITER_ROLE,
} = require('./constants');
const { getBytecodeHash } = require('@axelar-network/axelar-chains-config');

describe('InterchainTokenFactory', () => {
let wallet, otherWallet;
Expand Down Expand Up @@ -50,6 +51,40 @@ describe('InterchainTokenFactory', () => {
});
});

describe('Upgrade', async () => {
it('Should revert on upgrade from non-owner account', async () => {
await expectRevert(
(gasOptions) => tokenFactory.connect(otherWallet).upgrade(AddressZero, HashZero, '0x', gasOptions),
tokenFactory,
'NotOwner',
);
});

it('Should upgrade the implementation', async () => {
const newImplementation = await deployContract(wallet, 'InterchainTokenFactory', [service.address]);
const newImplementationCodeHash = await getBytecodeHash(newImplementation);
const setupParams = '0x';

await expect(tokenFactory.upgrade(newImplementation.address, newImplementationCodeHash, setupParams))
.to.emit(tokenFactory, 'Upgraded')
.withArgs(newImplementation.address);

expect(await tokenFactory.implementation()).to.eq(newImplementation.address);
});

it('Should upgrade the implementation with setup data', async () => {
const newImplementation = await deployContract(wallet, 'InterchainTokenFactory', [service.address]);
const newImplementationCodeHash = await getBytecodeHash(newImplementation);
const setupParams = '0x1234';

await expect(tokenFactory.upgrade(newImplementation.address, newImplementationCodeHash, setupParams))
.to.emit(tokenFactory, 'Upgraded')
.withArgs(newImplementation.address);

expect(await tokenFactory.implementation()).to.eq(newImplementation.address);
});
});

describe('Canonical Interchain Token Factory', async () => {
let token, tokenId, tokenManagerAddress;
const tokenCap = BigInt(1e18);
Expand Down

0 comments on commit c1e80a9

Please sign in to comment.