Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: test hardcoded constants #119

Merged
merged 97 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 96 commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
fbaded0
renamed folder and changed version
Foivos Jul 6, 2023
8a6d845
npmignore
Foivos Jul 6, 2023
607de5c
npmignore
Foivos Jul 6, 2023
52fc054
Merge remote-tracking branch 'origin/main' into feat/dist
Foivos Jul 6, 2023
f5b5f56
change version
Foivos Jul 6, 2023
4c5738d
using include pattern instead.
Foivos Jul 6, 2023
15e606b
Merge remote-tracking branch 'origin/main' into feat/dist0-1-1
Foivos Jul 6, 2023
d998f1b
Merge branch 'main' into feat/dist0-1-1
Foivos Jul 11, 2023
0548a6e
Fixed most of the things least auhority suggested.
Foivos Jul 11, 2023
8397b07
made lint happy
Foivos Jul 11, 2023
f2e5ea8
Apply suggestions from code review
milapsheth Jul 12, 2023
32ce490
fixed some bugs
Foivos Jul 19, 2023
80616c5
Merge remote-tracking branch 'origin/main' into feat/least-autority-f…
Foivos Jul 19, 2023
dc516fe
added events
Foivos Jul 19, 2023
d6fa384
rename set to transfer for distributor and operator
Foivos Jul 24, 2023
5cc8fbb
changed standardized token to always allow token managers to mint/bur…
Foivos Jul 24, 2023
ea255e0
using immutable storage for remoteAddressValidator address to save gas
Foivos Jul 24, 2023
09bf99a
Merge remote-tracking branch 'origin/main' into feat/gas-optimizations
Foivos Jul 24, 2023
650ca71
Added some recommended changes
Foivos Jul 26, 2023
c69e0a4
added milap's suggested changes
Foivos Jul 26, 2023
63a18e4
Merge remote-tracking branch 'origin/main' into feat/gas-optimizations
Foivos Jul 26, 2023
2993930
Fixed some names and some minor gas optimizations
Foivos Jul 26, 2023
9074ed1
prettier and lint
Foivos Jul 26, 2023
d3cb150
stash
Foivos Jul 27, 2023
53fe6fe
import .env in hardhat.config
Foivos Jul 27, 2023
7eb5207
trying to fix .env.example
Foivos Jul 27, 2023
bf603eb
Added some getters in IRemoteAddressValidator and removed useless che…
Foivos Jul 27, 2023
f1723c3
removed ternary operators
Foivos Jul 27, 2023
bc8ed59
made lint happy
Foivos Jul 27, 2023
7661e1f
Merge branch 'feat/gas-optimizations' into feat/use-create3-lib
Foivos Jul 27, 2023
4bf89db
made lint happy
Foivos Jul 27, 2023
512d126
Added a new token manager to handle fee on transfer and added some te…
Foivos Jul 27, 2023
9e43b1c
fixed the liquidity pool check.
Foivos Jul 28, 2023
ba29a2a
Merge remote-tracking branch 'origin/main' into feat/use-create3-lib
Foivos Jul 28, 2023
1e2aeb3
fix a duplication bug
Foivos Jul 28, 2023
6c62270
lint
Foivos Jul 28, 2023
30c1e53
added some more tests
Foivos Jul 28, 2023
51b70c1
Added more tests
Foivos Jul 28, 2023
6b3f5ed
Merge branch 'feat/use-create3-lib' into feat/fee-on-transfer-separate
Foivos Jul 28, 2023
3e6d85f
Added proper re-entrancy protection for fee on transfer token managers.
Foivos Jul 28, 2023
d4075b8
change to tx.origin for refunds
Foivos Jul 28, 2023
5d9d8ce
Added support for more kinds of addresses.
Foivos Jul 28, 2023
1b35cbf
some minor gas opts
Foivos Jul 28, 2023
412dce9
some more gas optimizations.
Foivos Jul 28, 2023
0a8519f
Added a getter for chain name to the remote address validator.
Foivos Jul 28, 2023
959e495
moved the tokenManager getter functionality to a separate contract wh…
Foivos Jul 28, 2023
0d09703
made lint happy
Foivos Jul 28, 2023
2e44518
Removed tokenManagerGetter and put params into tokenManagers
Foivos Jul 28, 2023
6027ffe
Added separate tokenManager interfaces
Foivos Jul 28, 2023
04041d1
addressed ackeeblockchains's 3.0 report
Foivos Aug 23, 2023
6ee5d06
prettier
Foivos Aug 23, 2023
5acf4a8
added interchain transfer methods to the service and unified receivin…
Foivos Aug 28, 2023
244ff61
made lint happy
Foivos Aug 28, 2023
4e56576
rename sendToken to interchainTransfer
Foivos Aug 29, 2023
a8dc8a4
changed sendToken everywhere
Foivos Aug 29, 2023
b210316
changed from uint256.max to a const
Foivos Aug 30, 2023
2f5adac
change setting to zero to delete for storage slots.
Foivos Sep 4, 2023
af4766a
rearange storage variables to save a bit of gas.
Foivos Sep 4, 2023
634581c
Removed unecesairy casts
Foivos Sep 4, 2023
141648b
made as many event params inexed as possible
Foivos Sep 4, 2023
602d531
Removed unused imports
Foivos Sep 4, 2023
0ec429e
domain separator is calculated each time.
Foivos Sep 4, 2023
f089d50
added some natspec
Foivos Sep 4, 2023
8053c76
added an example for using pre-existing custom tokens.
Foivos Sep 7, 2023
c19ec5a
added a comment
Foivos Sep 7, 2023
80f7637
feat: improved test coverage part one
Sep 28, 2023
4582807
feat: live testnet support
Oct 2, 2023
a18be9c
fix: remove exclusive mocha test
Oct 2, 2023
5cc9de0
fix: remove hardcoded gas options
Oct 2, 2023
0faf7a2
feat: increased test coverage part two
Oct 2, 2023
d7216ce
fix: remove comment
Oct 2, 2023
67f5f9b
feat: add test
Oct 2, 2023
7e9ebae
feat: increased test coverage part three
Oct 3, 2023
357f425
Merge branch 'main' into feat/test-coverage-one
re1ro Oct 3, 2023
a5fe901
fix(InvalidStandardizedToken): imports
re1ro Oct 3, 2023
5a89f3d
Merge branch 'feat/test-coverage-one' into feat/test-coverage-two
re1ro Oct 3, 2023
10a08c8
Merge branch 'feat/test-coverage-two' into feat/test-coverage-three
re1ro Oct 3, 2023
95dc1df
feat: address comments
Oct 5, 2023
6aa20e3
feat: test hardcoded constants
Oct 5, 2023
a2106e3
fix: ITS tests
Oct 6, 2023
8fb7b79
Merge branch 'main' into feat/test-coverage-one
milapsheth Oct 9, 2023
bedab79
fix: deployed bytecode
Oct 10, 2023
494a521
Merge branch 'feat/test-coverage-one' into feat/test-coverage-two
Oct 10, 2023
0744b80
Merge branch 'feat/test-coverage-two' into feat/test-coverage-three
Oct 10, 2023
25765d3
fix: tests
Oct 10, 2023
2f14552
Merge branch 'feat/test-coverage-two' into feat/test-coverage-three
Oct 10, 2023
6117c68
fix: tests
Oct 10, 2023
b8c2889
fix: remove broken test
Oct 10, 2023
7d26c10
Merge branch 'feat/test-coverage-two' into feat/test-coverage-three
Oct 10, 2023
d7401b1
Merge branch 'feat/test-coverage-three' into feat/test-hardcoded-cons…
Oct 10, 2023
4e47d29
feat: add tests
Oct 11, 2023
d195aa7
Merge branch 'feat/test-coverage-three' into feat/test-hardcoded-cons…
Oct 11, 2023
d82ca94
feat: temp file rename
Oct 11, 2023
c2dc7c9
feat: capitalize test file names
Oct 11, 2023
6f3b9cf
Merge branch 'main' into feat/test-hardcoded-constants
Oct 12, 2023
b87064e
fix: remove duplicate lockUnlockFee deploy functions
Oct 12, 2023
21c8e8c
fix: re-add hardcoded constants utils tests
Oct 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions contracts/test/HardCodedConstantsTest.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import { TokenManagerLiquidityPool } from '../token-manager/implementations/TokenManagerLiquidityPool.sol';
import { Distributable } from '../utils/Distributable.sol';
import { FlowLimit } from '../utils/FlowLimit.sol';
import { NoReEntrancy } from '../utils/NoReEntrancy.sol';
import { Operatable } from '../utils/Operatable.sol';
import { Pausable } from '../utils/Pausable.sol';

contract TestTokenManager is TokenManagerLiquidityPool {
string public constant NAME = 'TestTokenManager';

constructor(address interchainTokenService_) TokenManagerLiquidityPool(interchainTokenService_) {
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
require(TOKEN_ADDRESS_SLOT == uint256(keccak256('token-address')) - 1, 'invalid constant');
require(LIQUIDITY_POOL_SLOT == uint256(keccak256('liquidity-pool-slot')) - 1, 'invalid constant');
}
}

contract TestDistributable is Distributable {
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
string public constant NAME = 'TestDistributable';

constructor() {
require(DISTRIBUTOR_SLOT == uint256(keccak256('distributor')) - 1, 'invalid constant');
require(PROPOSED_DISTRIBUTOR_SLOT == uint256(keccak256('proposed-distributor')) - 1, 'invalid constant');
}
}

contract TestFlowLimit is FlowLimit {
string public constant NAME = 'TestFlowLimit';

constructor() {
require(FLOW_LIMIT_SLOT == uint256(keccak256('flow-limit')) - 1, 'invalid constant');
}
}

contract TestNoReEntrancy is NoReEntrancy {
string public constant NAME = 'TestNoReEntrancy';

constructor() {
require(ENTERED_SLOT == uint256(keccak256('entered')) - 1, 'invalid constant');
}
}

contract TestOperatable is Operatable {
string public constant NAME = 'TestOperatable';

constructor() {
require(OPERATOR_SLOT == uint256(keccak256('operator')) - 1, 'invalid constant');
require(PROPOSED_OPERATOR_SLOT == uint256(keccak256('proposed-operator')) - 1, 'invalid constant');
}
}

contract TestPausable is Pausable {
string public constant NAME = 'TestPausable';

constructor() {
require(PAUSE_SLOT == uint256(keccak256('paused')) - 1, 'invalid constant');
}
}
95 changes: 95 additions & 0 deletions test/StandardizedToken.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
'use strict';

const chai = require('chai');
const { ethers } = require('hardhat');
const {
Contract,
utils: { keccak256, toUtf8Bytes },
} = ethers;
const { expect } = chai;
const { getRandomBytes32, expectRevert, getGasOptions } = require('./utils');
const { deployContract } = require('../scripts/deploy');

const StandardizedToken = require('../artifacts/contracts/token-implementations/StandardizedToken.sol/StandardizedToken.json');
const StandardizedTokenProxy = require('../artifacts/contracts/proxies/StandardizedTokenProxy.sol/StandardizedTokenProxy.json');

describe('StandardizedToken', () => {
let standardizedToken, standardizedTokenDeployer;

const name = 'tokenName';
const symbol = 'tokenSymbol';
const decimals = 18;
const mintAmount = 123;

let token;
let tokenProxy;

let owner;

before(async () => {
const wallets = await ethers.getSigners();
owner = wallets[0];

standardizedToken = await deployContract(owner, 'StandardizedToken');
standardizedTokenDeployer = await deployContract(owner, 'StandardizedTokenDeployer', [standardizedToken.address]);

const salt = getRandomBytes32();

const tokenAddress = await standardizedTokenDeployer.deployedAddress(salt);

token = new Contract(tokenAddress, StandardizedToken.abi, owner);
tokenProxy = new Contract(tokenAddress, StandardizedTokenProxy.abi, owner);

await standardizedTokenDeployer
.deployStandardizedToken(salt, owner.address, owner.address, name, symbol, decimals, mintAmount, owner.address)
.then((tx) => tx.wait());
});

describe('Standardized Token Proxy', () => {
it('should revert if standardized token implementation is invalid', async () => {
const invalidStandardizedToken = await deployContract(owner, 'InvalidStandardizedToken');
standardizedTokenDeployer = await deployContract(owner, 'StandardizedTokenDeployer', [invalidStandardizedToken.address]);

const salt = getRandomBytes32();

await expect(
standardizedTokenDeployer.deployStandardizedToken(
salt,
owner.address,
owner.address,
name,
symbol,
decimals,
mintAmount,
owner.address,
getGasOptions(),
),
).to.be.reverted;
});

it('should revert if standardized token setup fails', async () => {
const params = '0x1234';
await expectRevert(
(gasOptions) => deployContract(owner, 'StandardizedTokenProxy', [standardizedToken.address, params, gasOptions]),
tokenProxy,
'SetupFailed',
);
});

it('should return the correct contract ID', async () => {
const contractID = await token.contractId();
const hash = keccak256(toUtf8Bytes('standardized-token'));
expect(contractID).to.equal(hash);
});
});

describe('Standardized Token', () => {
it('revert on setup if not called by the proxy', async () => {
const implementationAddress = await tokenProxy.implementation();
const implementation = new Contract(implementationAddress, StandardizedToken.abi, owner);

const params = '0x';
await expectRevert((gasOptions) => implementation.setup(params, gasOptions), token, 'NotProxy');
});
});
});
123 changes: 123 additions & 0 deletions test/TokenManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
'use strict';

const chai = require('chai');
const { ethers } = require('hardhat');
const {
utils: { toUtf8Bytes, defaultAbiCoder },
constants: { AddressZero },
} = ethers;
const { expect } = chai;
const { expectRevert } = require('./utils');
const { deployContract } = require('../scripts/deploy');

describe('Token Manager', () => {
let owner, user, token, service, liquidityPool;
let tokenManagerLockUnlock, tokenManagerMintBurn, tokenManagerLiquidityPool, tokenManagerLockUnlockFeeOnTransfer;

before(async () => {
[owner, user, token, service, liquidityPool] = await ethers.getSigners();

tokenManagerLockUnlock = await deployContract(owner, `TokenManagerLockUnlock`, [service.address]);
tokenManagerMintBurn = await deployContract(owner, `TokenManagerMintBurn`, [service.address]);
tokenManagerLiquidityPool = await deployContract(owner, `TokenManagerLiquidityPool`, [service.address]);
tokenManagerLockUnlockFeeOnTransfer = await deployContract(owner, `TokenManagerLockUnlockFee`, [service.address]);
});

it('Should calculate hardcoded constants correctly', async () => {
await expect(deployContract(owner, `TestTokenManager`, [service.address])).to.not.be.reverted;
});

it('Should revert on token manager deployment with invalid service address', async () => {
await expectRevert(
(gasOptions) => deployContract(owner, `TokenManagerLockUnlock`, [AddressZero, gasOptions]),
tokenManagerLockUnlock,
'TokenLinkerZeroAddress',
);
});

it('Should revert on setup if not called by the proxy', async () => {
const params = '0x';
await expectRevert((gasOptions) => tokenManagerLockUnlock.setup(params, gasOptions), tokenManagerLockUnlock, 'NotProxy');
});

it('Should revert on transmitInterchainTransfer if not called by the token', async () => {
const sender = owner.address;
const destinationChain = 'Dest Chain';
const destinationAddress = toUtf8Bytes(user.address);
const amount = 10;
const metadata = '0x00000000';

await expectRevert(
(gasOptions) =>
tokenManagerLockUnlock.transmitInterchainTransfer(
sender,
destinationChain,
destinationAddress,
amount,
metadata,
gasOptions,
),
tokenManagerLockUnlock,
'NotToken',
);
});

it('Should revert on giveToken if not called by the service', async () => {
const destinationAddress = user.address;
const amount = 10;

await expectRevert(
(gasOptions) => tokenManagerLockUnlock.giveToken(destinationAddress, amount, gasOptions),
tokenManagerLockUnlock,
'NotService',
);
});

it('Should revert on takeToken if not called by the service', async () => {
const sourceAddress = user.address;
const amount = 10;

await expectRevert(
(gasOptions) => tokenManagerLockUnlock.takeToken(sourceAddress, amount, gasOptions),
tokenManagerLockUnlock,
'NotService',
);
});

it('Should revert on setFlowLimit if not called by the operator', async () => {
const flowLimit = 100;

await expectRevert(
(gasOptions) => tokenManagerLockUnlock.setFlowLimit(flowLimit, gasOptions),
tokenManagerLockUnlock,
'NotOperator',
);
});

it('Should return the correct parameters for lock/unlock token manager', async () => {
const expectedParams = defaultAbiCoder.encode(['bytes', 'address'], [toUtf8Bytes(owner.address), token.address]);
const params = await tokenManagerLockUnlock.getParams(toUtf8Bytes(owner.address), token.address);
expect(expectedParams).to.eq(params);
});

it('Should return the correct parameters for mint/burn token manager', async () => {
const expectedParams = defaultAbiCoder.encode(['bytes', 'address'], [toUtf8Bytes(owner.address), token.address]);
const params = await tokenManagerMintBurn.getParams(toUtf8Bytes(owner.address), token.address);
expect(expectedParams).to.eq(params);
});

it('Should return the correct parameters for liquidity pool token manager', async () => {
const expectedParams = defaultAbiCoder.encode(
['bytes', 'address', 'address'],
[toUtf8Bytes(owner.address), token.address, liquidityPool.address],
);
const params = await tokenManagerLiquidityPool.getParams(toUtf8Bytes(owner.address), token.address, liquidityPool.address);
expect(expectedParams).to.eq(params);
});

it('Should return the correct parameters for fee on transfer token manager', async () => {
const expectedParams = defaultAbiCoder.encode(['bytes', 'address'], [toUtf8Bytes(owner.address), token.address]);
const params = await tokenManagerLockUnlockFeeOnTransfer.getParams(toUtf8Bytes(owner.address), token.address);
expect(expectedParams).to.eq(params);
});
});
24 changes: 0 additions & 24 deletions test/tokenService.js → test/TokenService.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,30 +67,6 @@ describe('Interchain Token Service', () => {
return [token, tokenManager, tokenId];
};

deployFunctions.lockUnlockFee = async function deployNewLockUnlock(
tokenName,
tokenSymbol,
tokenDecimals,
mintAmount = 0,
skipApprove = false,
) {
const salt = getRandomBytes32();
const tokenId = await service.getCustomTokenId(wallet.address, salt);
const tokenManager = new Contract(await service.getTokenManagerAddress(tokenId), TokenManager.abi, wallet);

const token = await deployContract(wallet, 'FeeOnTransferTokenTest', [tokenName, tokenSymbol, tokenDecimals, tokenManager.address]);
const params = defaultAbiCoder.encode(['bytes', 'address'], [wallet.address, token.address]);

await (await service.deployCustomTokenManager(salt, LOCK_UNLOCK_FEE_ON_TRANSFER, params)).wait();

if (mintAmount > 0) {
await (await token.mint(wallet.address, mintAmount)).wait();
if (!skipApprove) await (await token.approve(tokenManager.address, mintAmount)).wait();
}

return [token, tokenManager, tokenId];
};

deployFunctions.lockUnlockFee = async function deployNewLockUnlock(
tokenName,
tokenSymbol,
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion test/UtilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const { time } = require('@nomicfoundation/hardhat-network-helpers');
const { Wallet, Contract } = ethers;
const { AddressZero } = ethers.constants;
const { defaultAbiCoder, arrayify, toUtf8Bytes, hexlify } = ethers.utils;

const { expect } = chai;
const { getRandomBytes32, expectRevert } = require('./utils');
const { deployContract } = require('../scripts/deploy');
Expand Down
Loading