Skip to content

Commit

Permalink
fix: ITS tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dean Amiel committed Oct 6, 2023
1 parent 5a89f3d commit a2106e3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
12 changes: 8 additions & 4 deletions contracts/interchain-token-service/InterchainTokenService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ contract InterchainTokenService is

address internal immutable implementationLockUnlock;
address internal immutable implementationMintBurn;
address internal immutable implementationMintBurnFrom;
address internal immutable implementationLockUnlockFee;
address internal immutable implementationLiquidityPool;
IAxelarGasService public immutable gasService;
Expand Down Expand Up @@ -98,8 +99,9 @@ contract InterchainTokenService is

if (tokenManagerImplementations.length != uint256(type(TokenManagerType).max) + 1) revert LengthMismatch();

implementationLockUnlock = _sanitizeTokenManagerImplementation(tokenManagerImplementations, TokenManagerType.LOCK_UNLOCK);
implementationMintBurn = _sanitizeTokenManagerImplementation(tokenManagerImplementations, TokenManagerType.MINT_BURN);
implementationMintBurnFrom = _sanitizeTokenManagerImplementation(tokenManagerImplementations, TokenManagerType.MINT_BURN_FROM);
implementationLockUnlock = _sanitizeTokenManagerImplementation(tokenManagerImplementations, TokenManagerType.LOCK_UNLOCK);
implementationLockUnlockFee = _sanitizeTokenManagerImplementation(
tokenManagerImplementations,
TokenManagerType.LOCK_UNLOCK_FEE_ON_TRANSFER
Expand Down Expand Up @@ -213,10 +215,12 @@ contract InterchainTokenService is
*/
function getImplementation(uint256 tokenManagerType) external view returns (address tokenManagerAddress) {
if (tokenManagerType > uint256(type(TokenManagerType).max)) revert InvalidImplementation();
if (TokenManagerType(tokenManagerType) == TokenManagerType.LOCK_UNLOCK) {
return implementationLockUnlock;
} else if (TokenManagerType(tokenManagerType) == TokenManagerType.MINT_BURN) {
if (TokenManagerType(tokenManagerType) == TokenManagerType.MINT_BURN) {
return implementationMintBurn;
} else if (TokenManagerType(tokenManagerType) == TokenManagerType.MINT_BURN_FROM) {
return implementationMintBurnFrom;
} else if (TokenManagerType(tokenManagerType) == TokenManagerType.LOCK_UNLOCK) {
return implementationLockUnlock;
} else if (TokenManagerType(tokenManagerType) == TokenManagerType.LOCK_UNLOCK_FEE_ON_TRANSFER) {
return implementationLockUnlockFee;
} else if (TokenManagerType(tokenManagerType) == TokenManagerType.LIQUIDITY_POOL) {
Expand Down
16 changes: 12 additions & 4 deletions test/tokenService.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ describe('Interchain Token Service', () => {

it('Should revert on invalid token manager implementation length', async () => {
tokenManagerImplementations.push(wallet);

await expectRevert(
(gasOptions) =>
deployInterchainTokenService(
Expand All @@ -292,6 +293,7 @@ describe('Interchain Token Service', () => {
service,
'LengthMismatch',
);

tokenManagerImplementations.pop();
});

Expand All @@ -308,18 +310,20 @@ describe('Interchain Token Service', () => {
deploymentKey,
);

const length = tokenManagerImplementations.length;
let implementation;

for (let i = 0; i < 4; i++) {
for (let i = 0; i < length; i++) {
implementation = await service.getImplementation(i);
expect(implementation).to.eq(tokenManagerImplementations[i].address);
}

await expectRevert((gasOptions) => service.getImplementation(4, gasOptions), service, 'InvalidImplementation');
await expectRevert((gasOptions) => service.getImplementation(length, gasOptions), service, 'InvalidImplementation');
});

it('Should revert on invalid token manager implementation', async () => {
tokenManagerImplementations.pop();
const toRemove = tokenManagerImplementations.pop();

await expectRevert(
(gasOptions) =>
deployInterchainTokenService(
Expand All @@ -337,10 +341,14 @@ describe('Interchain Token Service', () => {
service,
'ZeroAddress',
);

tokenManagerImplementations.push(toRemove);
});

it('Should revert on duplicate token manager type', async () => {
tokenManagerImplementations[3] = tokenManagerImplementations[2];
const length = tokenManagerImplementations.length;
tokenManagerImplementations[length - 1] = tokenManagerImplementations[length - 2];

await expectRevert(
(gasOptions) =>
deployInterchainTokenService(
Expand Down

0 comments on commit a2106e3

Please sign in to comment.