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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'origin/main' into feat/use-create3-lib
Foivos committed Jul 28, 2023
commit ba29a2a1175cb6500d9a025081fd7d08fc4d8356
1 change: 0 additions & 1 deletion .env.example

This file was deleted.

60 changes: 60 additions & 0 deletions .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Run Coverage Tests

on:
push:
branches: ['main']

jobs:
build:
name: 'Run Coverage Tests'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 18.x

- name: Install Dependencies
run: npm ci

- name: Build
run: npm run build

- name: Run Coverage Tests
run: npm run coverage

- name: Upload artifact
uses: actions/upload-pages-artifact@v2
with:
path: 'coverage/lcov-report'

deploy:
name: 'Deploy Coverage Report'
needs: build

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow one concurrent deployment
concurrency:
group: 'pages'
cancel-in-progress: true

runs-on: ubuntu-latest
steps:
- name: Download coverage artifact
uses: actions/download-artifact@v2
with:
name: github-pages

- name: Setup GitHub Pages
uses: actions/configure-pages@v2

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
3 changes: 0 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -23,8 +23,5 @@ jobs:
- name: Install Dependencies
run: npm ci

- name: Copy .env
run: cp .env.example .env

- name: Test
run: npm run test
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -15,3 +15,11 @@ npm run build

npm run test
```

## Test Coverage Report

For the most recent test coverage report of the `main` branch, please visit the following [page](https://axelarnetwork.github.io/interchain-token-service/).

## Deployment Guide

To learn more about the deployment process, please refer to [this repo](https://github.com/axelarnetwork/axelar-contract-deployments).
77 changes: 59 additions & 18 deletions contracts/remote-address-validator/RemoteAddressValidator.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import { IRemoteAddressValidator } from '../interfaces/IRemoteAddressValidator.sol';
import { AddressToString } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/utils/AddressString.sol';
import { Upgradable } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/upgradable/Upgradable.sol';
@@ -14,11 +15,16 @@ contract RemoteAddressValidator is IRemoteAddressValidator, Upgradable {

mapping(string => bytes32) public remoteAddressHashes;
mapping(string => string) public remoteAddresses;
mapping(string => bool) public supportedByGateway;

address public immutable interchainTokenServiceAddress;
bytes32 public immutable interchainTokenServiceAddressHash;

/**
* @dev Store the interchain token service address as string across two immutable variables to avoid recomputation and save gas
*/
uint256 private immutable interchainTokenServiceAddress1;
uint256 private immutable interchainTokenServiceAddress2;
mapping(string => bool) public supportedByGateway;

bytes32 private constant CONTRACT_ID = keccak256('remote-address-validator');

@@ -28,15 +34,20 @@ contract RemoteAddressValidator is IRemoteAddressValidator, Upgradable {
*/
constructor(address _interchainTokenServiceAddress) {
if (_interchainTokenServiceAddress == address(0)) revert ZeroAddress();

interchainTokenServiceAddress = _interchainTokenServiceAddress;

string memory interchainTokenServiceAddressString = interchainTokenServiceAddress.toString();
interchainTokenServiceAddressHash = keccak256(bytes(_lowerCase(interchainTokenServiceAddressString)));
interchainTokenServiceAddressHash = keccak256(bytes(interchainTokenServiceAddressString));

uint256 p1;
uint256 p2;

assembly {
p1 := mload(add(interchainTokenServiceAddressString, 32))
p2 := mload(add(interchainTokenServiceAddressString, 64))
}

interchainTokenServiceAddress1 = p1;
interchainTokenServiceAddress2 = p2;
}
@@ -51,7 +62,9 @@ contract RemoteAddressValidator is IRemoteAddressValidator, Upgradable {
function _setup(bytes calldata params) internal override {
(string[] memory trustedChainNames, string[] memory trustedAddresses) = abi.decode(params, (string[], string[]));
uint256 length = trustedChainNames.length;

if (length != trustedAddresses.length) revert LengthMismatch();

for (uint256 i; i < length; ++i) {
addTrustedAddress(trustedChainNames[i], trustedAddresses[i]);
}
@@ -64,10 +77,12 @@ contract RemoteAddressValidator is IRemoteAddressValidator, Upgradable {
*/
function _lowerCase(string memory s) internal pure returns (string memory) {
uint256 length = bytes(s).length;

for (uint256 i; i < length; i++) {
uint8 b = uint8(bytes(s)[i]);
if ((b >= 65) && (b <= 70)) bytes(s)[i] = bytes1(b + uint8(32));
}

return s;
}

@@ -81,43 +96,64 @@ contract RemoteAddressValidator is IRemoteAddressValidator, Upgradable {
}
}

/**
* @dev Return the interchain token service address as a string by constructing it from the two immutable variables caching it
*/
function _interchainTokenServiceAddressString() internal view returns (string memory interchainTokenServiceAddressString) {
interchainTokenServiceAddressString = new string(42);

uint256 p1 = interchainTokenServiceAddress1;
uint256 p2 = interchainTokenServiceAddress2;

assembly {
mstore(add(interchainTokenServiceAddressString, 32), p1)
mstore(add(interchainTokenServiceAddressString, 64), p2)
}
}

/**
* @dev Validates that the sender is a valid interchain token service address
* @param sourceChain Source chain of the transaction
* @param sourceAddress Source address of the transaction
* @return bool true if the sender is validated, false otherwise
*/
function validateSender(string calldata sourceChain, string calldata sourceAddress) external view returns (bool) {
string memory sourceAddressLC = _lowerCase(sourceAddress);
bytes32 sourceAddressHash = keccak256(bytes(sourceAddressLC));
string memory sourceAddressNormalized = _lowerCase(sourceAddress);
bytes32 sourceAddressHash = keccak256(bytes(sourceAddressNormalized));

if (sourceAddressHash == interchainTokenServiceAddressHash) {
return true;
}

return sourceAddressHash == remoteAddressHashes[sourceChain];
}

/**
* @dev Adds a trusted interchain token service address for the specified chain
* @param chain Chain name of the interchain token service
* @param addr Interchain token service address to be added
* @param sourceChain Chain name of the interchain token service
* @param sourceAddress Interchain token service address to be added
*/
function addTrustedAddress(string memory chain, string memory addr) public onlyOwner {
if (bytes(chain).length == 0) revert ZeroStringLength();
if (bytes(addr).length == 0) revert ZeroStringLength();
remoteAddressHashes[chain] = keccak256(bytes(_lowerCase(addr)));
remoteAddresses[chain] = addr;
emit TrustedAddressAdded(chain, addr);
function addTrustedAddress(string memory sourceChain, string memory sourceAddress) public onlyOwner {
if (bytes(sourceChain).length == 0) revert ZeroStringLength();
if (bytes(sourceAddress).length == 0) revert ZeroStringLength();

remoteAddressHashes[sourceChain] = keccak256(bytes(_lowerCase(sourceAddress)));
remoteAddresses[sourceChain] = sourceAddress;

emit TrustedAddressAdded(sourceChain, sourceAddress);
}

/**
* @dev Removes a trusted interchain token service address
* @param chain Chain name of the interchain token service to be removed
* @param sourceChain Chain name of the interchain token service to be removed
*/
function removeTrustedAddress(string calldata chain) external onlyOwner {
if (bytes(chain).length == 0) revert ZeroStringLength();
remoteAddressHashes[chain] = bytes32(0);
remoteAddresses[chain] = '';
emit TrustedAddressRemoved(chain);
function removeTrustedAddress(string calldata sourceChain) external onlyOwner {
if (bytes(sourceChain).length == 0) revert ZeroStringLength();

remoteAddressHashes[sourceChain] = bytes32(0);
remoteAddresses[sourceChain] = '';

emit TrustedAddressRemoved(sourceChain);
}

/**
@@ -126,9 +162,11 @@ contract RemoteAddressValidator is IRemoteAddressValidator, Upgradable {
*/
function addGatewaySupportedChains(string[] calldata chainNames) external onlyOwner {
uint256 length = chainNames.length;

for (uint256 i; i < length; ++i) {
string calldata chainName = chainNames[i];
supportedByGateway[chainName] = true;

emit GatewaySupportedChainAdded(chainName);
}
}
@@ -139,9 +177,11 @@ contract RemoteAddressValidator is IRemoteAddressValidator, Upgradable {
*/
function removeGatewaySupportedChains(string[] calldata chainNames) external onlyOwner {
uint256 length = chainNames.length;

for (uint256 i; i < length; ++i) {
string calldata chainName = chainNames[i];
supportedByGateway[chainName] = false;

emit GatewaySupportedChainRemoved(chainName);
}
}
@@ -153,6 +193,7 @@ contract RemoteAddressValidator is IRemoteAddressValidator, Upgradable {
*/
function getRemoteAddress(string calldata chainName) external view returns (string memory remoteAddress) {
remoteAddress = remoteAddresses[chainName];

if (bytes(remoteAddress).length == 0) {
remoteAddress = _interchainTokenServiceAddressString();
}
14 changes: 9 additions & 5 deletions contracts/token-implementations/StandardizedToken.sol
Original file line number Diff line number Diff line change
@@ -3,11 +3,11 @@
pragma solidity ^0.8.0;

import { IERC20BurnableMintable } from '../interfaces/IERC20BurnableMintable.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 { ITokenManager } from '../interfaces/ITokenManager.sol';
import { Implementation } from '../utils/Implementation.sol';
import { Distributable } from '../utils/Distributable.sol';

@@ -16,7 +16,7 @@ import { Distributable } from '../utils/Distributable.sol';
* @notice This contract implements a standardized token which extends InterchainToken functionality.
* This contract also inherits Distributable and Implementation logic.
*/
contract StandardizedToken is InterchainToken, ERC20Permit, Implementation, Distributable {
contract StandardizedToken is IERC20BurnableMintable, InterchainToken, ERC20Permit, Implementation, Distributable {
using AddressBytesUtils for bytes;

address internal tokenManager_;
@@ -30,6 +30,7 @@ contract StandardizedToken is InterchainToken, ERC20Permit, Implementation, Dist
if (msg.sender != tokenManager_) {
if (msg.sender != distributor()) revert NotDistributor();
}

_;
}

@@ -62,16 +63,19 @@ contract StandardizedToken is InterchainToken, ERC20Permit, Implementation, Dist
params,
(address, address, string, string, uint8)
);
_setDistributor(distributor_);

tokenManager_ = tokenManagerAddress;
_setDomainTypeSignatureHash(tokenName);
name = tokenName;

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

if (mintAmount > 0 && mintTo != address(0)) {
_mint(mintTo, mintAmount);
}
}
17 changes: 10 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -20,9 +20,12 @@
],
"author": "axelar-network",
"license": "MIT",
"engines": {
"node": ">=16"
},
"dependencies": {
"@axelar-network/axelar-cgp-solidity": "^5.0.0",
"@axelar-network/axelar-gmp-sdk-solidity": "^4.0.0"
"@axelar-network/axelar-cgp-solidity": "5.0.0",
"@axelar-network/axelar-gmp-sdk-solidity": "4.0.2"
},
"devDependencies": {
"@axelar-network/axelar-contract-deployments": "git://github.com/axelarnetwork/axelar-contract-deployments.git#f2d55c39967c8a55c7f9ac775a250cb8be6d74d9",
@@ -42,6 +45,7 @@
},
"description": "Interchain token service for EVM chains to faciliate cross-chain token transfers and contract calls",
"files": [
"artifacts",
"contracts",
"dist",
"docs",
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.