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: improved test coverage part two #113

Merged
merged 82 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 81 commits
Commits
Show all changes
82 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
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
95dc1df
feat: address comments
Oct 5, 2023
a2106e3
fix: ITS tests
Oct 6, 2023
8fb7b79
Merge branch 'main' into feat/test-coverage-one
milapsheth Oct 9, 2023
494a521
Merge branch 'feat/test-coverage-one' into feat/test-coverage-two
Oct 10, 2023
25765d3
fix: tests
Oct 10, 2023
b8c2889
fix: remove broken test
Oct 10, 2023
d3a053e
Merge branch 'main' into feat/test-coverage-two
milapsheth 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
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ contract InterchainTokenService is IInterchainTokenService, Upgradable, Operatab
function _decodeMetadata(bytes memory metadata) internal pure returns (uint32 version, bytes memory data) {
data = new bytes(metadata.length - 4);
assembly {
version := shr(224, mload(data))
version := shr(224, mload(add(metadata, 32)))
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
}
if (data.length == 0) return (version, data);
uint256 n = (data.length - 1) / 32;
Expand Down
98 changes: 98 additions & 0 deletions contracts/test/InvalidStandardizedToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import { IERC20MintableBurnable } from '../interfaces/IERC20MintableBurnable.sol';
import { ITokenManager } from '../interfaces/ITokenManager.sol';

import { InterchainToken } from '../interchain-token/InterchainToken.sol';
import { ERC20Permit } from '../token-implementations/ERC20Permit.sol';
import { AddressBytesUtils } from '../libraries/AddressBytesUtils.sol';
import { Implementation } from '../utils/Implementation.sol';
import { Distributable } from '../utils/Distributable.sol';

contract InvalidStandardizedToken is IERC20MintableBurnable, InterchainToken, ERC20Permit, Implementation, Distributable {
using AddressBytesUtils for bytes;

string public name;
string public symbol;
uint8 public decimals;
address internal tokenManager_;

bytes32 private constant CONTRACT_ID = keccak256('invalid-standardized-token');

modifier onlyDistributorOrTokenManager() {
if (msg.sender != tokenManager_) {
if (msg.sender != distributor()) revert NotDistributor();
}

_;
}

/**
* @notice Getter for the contract id.
*/
function contractId() external pure returns (bytes32) {
return CONTRACT_ID;
}

/**
* @notice Returns the token manager for this token
* @return ITokenManager The token manager contract
*/
function tokenManager() public view override returns (ITokenManager) {
return ITokenManager(tokenManager_);
}

/**
* @notice Setup function to initialize contract parameters
* @param params The setup parameters in bytes
* The setup params include tokenManager, distributor, tokenName, symbol, decimals, mintAmount and mintTo
*/
function setup(bytes calldata params) external override onlyProxy {
{
address distributor_;
address tokenManagerAddress;
string memory tokenName;
(tokenManagerAddress, distributor_, tokenName, symbol, decimals) = abi.decode(
params,
(address, address, string, string, uint8)
);

tokenManager_ = tokenManagerAddress;
name = tokenName;

_setDistributor(distributor_);
_setNameHash(tokenName);
}
{
uint256 mintAmount;
address mintTo;
(, , , , , mintAmount, mintTo) = abi.decode(params, (address, address, string, string, uint8, uint256, address));

if (mintAmount > 0 && mintTo != address(0)) {
_mint(mintTo, mintAmount);
}
}
}

/**
* @notice Function to mint new tokens
* Can only be called by the distributor address.
* @param account The address that will receive the minted tokens
* @param amount The amount of tokens to mint
*/
function mint(address account, uint256 amount) external onlyDistributorOrTokenManager {
_mint(account, amount);
}

/**
* @notice Function to burn tokens
* Can only be called by the distributor address.
* @param account The address that will have its tokens burnt
* @param amount The amount of tokens to burn
*/
function burn(address account, uint256 amount) external onlyDistributorOrTokenManager {
_burn(account, amount);
}
}
4 changes: 4 additions & 0 deletions contracts/test/MockAxelarGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ contract MockAxelarGateway is IMockAxelarGateway {
_addressStorage[_getTokenAddressKey(symbol)] = tokenAddress;
}

function setCommandExecuted(bytes32 commandId, bool executed) external {
_setCommandExecuted(commandId, executed);
}

/********************\
|* Pure Key Getters *|
\********************/
Expand Down
5 changes: 5 additions & 0 deletions contracts/test/utils/MulticallTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ contract MulticallTest is Multicall {
return nonce_;
}

function function3() external pure {
// solhint-disable-next-line reason-string
revert();
}

function multicallTest(bytes[] calldata data) external {
lastMulticallReturns = multicall(data);
}
Expand Down
3 changes: 2 additions & 1 deletion scripts/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { deployCreate3Contract, getCreate3Address } = require('@axelar-network/ax

async function deployContract(wallet, contractName, args = []) {
const factory = await ethers.getContractFactory(contractName, wallet);
const contract = await factory.deploy(...args);
const contract = await factory.deploy(...args).then((d) => d.deployed());

return contract;
}
Expand Down Expand Up @@ -103,6 +103,7 @@ module.exports = {
deployContract,
deployRemoteAddressValidator,
deployMockGateway,
deployTokenManagerImplementations,
deployGasService,
deployInterchainTokenService,
deployAll,
Expand Down
104 changes: 104 additions & 0 deletions test/ERC20.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
'use strict';

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

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

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

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

let token;

let owner, user;

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

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);

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

it('should increase and decrease allowance', async () => {
const initialAllowance = await token.allowance(user.address, owner.address);
expect(initialAllowance).to.eq(0);

await expect(token.connect(user).increaseAllowance(owner.address, MaxUint256))
.to.emit(token, 'Approval')
.withArgs(user.address, owner.address, MaxUint256);

const increasedAllowance = await token.allowance(user.address, owner.address);
expect(increasedAllowance).to.eq(MaxUint256);

await expect(token.connect(user).decreaseAllowance(owner.address, MaxUint256))
.to.emit(token, 'Approval')
.withArgs(user.address, owner.address, 0);

const finalAllowance = await token.allowance(user.address, owner.address);
expect(finalAllowance).to.eq(0);
});

it('should revert on approve with invalid owner or sender', async () => {
await expectRevert(
(gasOptions) => token.connect(owner).transferFrom(AddressZero, owner.address, 0, gasOptions),
token,
'InvalidAccount',
);

await expectRevert(
(gasOptions) => token.connect(user).increaseAllowance(AddressZero, MaxUint256, gasOptions),
token,
'InvalidAccount',
);
});

it('should revert on transfer to invalid address', async () => {
const initialAllowance = await token.allowance(user.address, owner.address);
expect(initialAllowance).to.eq(0);

await expect(token.connect(user).increaseAllowance(owner.address, MaxUint256))
.to.emit(token, 'Approval')
.withArgs(user.address, owner.address, MaxUint256);

const increasedAllowance = await token.allowance(user.address, owner.address);
expect(increasedAllowance).to.eq(MaxUint256);

const amount = 100;

await expectRevert(
(gasOptions) => token.connect(owner).transferFrom(user.address, AddressZero, amount, gasOptions),
token,
'InvalidAccount',
);
});

it('should revert mint or burn to invalid address', async () => {
const amount = 100;
await expectRevert((gasOptions) => token.mint(AddressZero, amount, gasOptions), token, 'InvalidAccount');
await expectRevert((gasOptions) => token.burn(AddressZero, amount, gasOptions), token, 'InvalidAccount');
});
});
Loading