Skip to content

Commit

Permalink
feat: add solidity multi protocol xCall (#86)
Browse files Browse the repository at this point in the history
* feat: setup foundry structure (#79)

* remove msg encoding in encodeCSMessageResponse

* chore: forge init

* forge install: forge-std

v1.6.1

* initial foundry setup

* forge install: openzeppelin-contracts-upgradeable

v4.9.3

* forge install: openzeppelin-contracts

v4.9.3

* add contract setup script for Callservice for Xcall

* add initial test setup for Xcall

* feat: testcase set admin (#80)

* add setAdmin testCases
- setAdmin by Owner
- setAdmin by unauthorized caller


---------

Co-authored-by: AntonAndell <[email protected]>

* feat: testcase set protocol fee (#81)

* add setProtocolFee and getProtocolFee testCases
- setProtocolFee by Owner
- setProtocolFee by added admin
- setProtocolFee by unauthrorized user

---------

Co-authored-by: AntonAndell <[email protected]>

* feat: testcase set protocol fee handler (#82)

* add setProtocolFeeHandler and getProtocolFeeHandler testCases
- setProtocolFeeHandler by Owner/Admin
- setProtocolFee by unauthrorized user

---------

Co-authored-by: AntonAndell <[email protected]>

* fix: add default connection setter (#87)

* add defaultConnection check on sendCallMessage

* add defaultConnection setter for xCall

* add revert messages on require()

* fix: rlp encode library encoding fix for protocols (#89)

* update encodeCSMessageRequest with protocol encoded code

* feat: handle requests multiple testcases (#90)

* add defaultConnection check on sendCallMessage

* add defaultConnection setter for xCall

* add revert messages on require()

* - add CallMessage eventLog for assertion
- Add Connection instances
- Add required const variables for netTo for NID and dstAccount for addr

* add testCase for HandleResponse
- DefaultProtocol with access
- DefaultProtocol with unauthorized access

* TestCases
- handleResponse with singleProtocol
- handleResponse with singleProtocol by unauthorized

* TestCases
- handleResponse with MultiProtocol

---------

Co-authored-by: AntonAndell <[email protected]>

* add successfulResponses record for responses

* update successfulResponses variable after response is success

* feat: execute call testcases (#91)

* TestCases
- executeCall using singleProtocol

* Add `CallExecuted` eventlogs for assertions

* TestCases
- executeCall using defaultProtocol

* TestCases
- executeCall using multiProtocols

* fix: clearing out unused code (#98)

* fix: clearing out unused code

* fix: clearing out contract part in library

---------

Co-authored-by: AntonAndell <[email protected]>

* docs: solidity xcall deployment (#99)

* update solidity document to deploy tthe contract as well as getting ready with forge commands

* update solidity document to deploy tthe contract as well as getting ready with forge commands

* feat: rollback testcases (#92)


* TestCases
- Rollback using singleProtocol

* TestCases
- Rollback using DefaultProtocol
- Rollback using DefaultProtocol NotAuthorized

* TestCases
- Rollback using MultiProtocol
- Rollback with SuccessMessage

* fix rollbackSuccess testcase to remove rollbackMessage eventlog

* remove rollbackMessage eventlogs from executeCall()

* feat: execute rollback testcases (#93)

* - Fix variables
- Fix Imports
- TestCases
    - ExecuteRollback using SingleProtocol
    - ExecuteRollback with DefaultProtocol
    - ExecuteRollback using MultiProtocol

* fix executeRollack testcases

* fix: testcase for send call message (#88)

* fix sendCallMessageSingleProtocol testCase

* add `CallMessgeSent` eventLog for test

* add testCase for sendMessage using multiProtocol

* add testCase for sendMessage using defaultProtocol

* Fix expectCall on sendMessage TestCases

---------

Co-authored-by: AntonAndell <[email protected]>

* fix: deployment script updated (#100)

* fix: deployment script updated

* fix: foundry.toml

* fix: nid taken from env

* update deployment script to add the setup params for xcall-multi

* update deploy script on shellScript file to deploy the contracts easily from CLI

* add .env example file to follow to deploy the xcall

---------

Co-authored-by: sdpbhandari <[email protected]>

* fix: add verify success test cases (#101)

* fix imports error after merge

* Fix verifySuccess()
Add assert on verifySuccess for rollback tests
Add assert on verifySuccess for executeRollback tests

* tests: Fix testExecuteRollbackMultiProtocol test

* feat: ci add solidity code coverages (#140)

* ci: add solidity coverage workflow

* ci: test codcov workflow

---------

Co-authored-by: Deepak Bomjan <[email protected]>

* refactor: evm folder structure

* fix: solidity xcall cod coverage

* feat: added evm multiprotocol dapp

* fix: removed unnecessary imports

* fix: remove cache file

* fix: add cache to gitignore

* fix: Add full expects of sendMessage to connections

* Ignore libraries in solidity code coverage

---------

Co-authored-by: Sudeep Bhandari <[email protected]>
Co-authored-by: gcranju <[email protected]>
Co-authored-by: Deepak Bomjan <[email protected]>
Co-authored-by: red__larva <[email protected]>
Co-authored-by: qwerty0789 <[email protected]>
  • Loading branch information
6 people authored Oct 23, 2023
1 parent caaf7a0 commit 6779754
Show file tree
Hide file tree
Showing 37 changed files with 3,783 additions and 1 deletion.
48 changes: 48 additions & 0 deletions .github/workflows/solidity-contracts-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Solidity Contracts tests

on:
pull_request:
branches:
- "**"
paths:
- "contracts/evm/**"
- ".github/workflows/solidity-cov.yml"
push:
branches:
- "**"

env:
FOUNDRY_PROFILE: ci

defaults:
run:
working-directory: contracts/evm

jobs:
check:
strategy:
fail-fast: true

name: xCall-Multi Solidity Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Run Forge build
run: |
forge --version
forge remappings
forge build --sizes
id: build

- name: Run Forge tests
run: |
forge test -vvv
id: test
53 changes: 53 additions & 0 deletions .github/workflows/solidity-cov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Solidity contracts Codecov

env:
FOUNDRY_PROFILE: ci

on:
pull_request:
branches:
- "**"
paths:
- "contracts/evm/**"
- ".github/workflows/solidity-cov.yml"
push:
branches:
- "**"

defaults:
run:
working-directory: contracts/evm

jobs:
code-coverage:
runs-on: ubuntu-latest
env:
CARGO_TERM_COLOR: always
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Build Contracts
run: |
forge remappings
forge build
- name: Generate code coverage
run: |
export PATH=$PATH:$HOME/.config/.foundry/bin
forge coverage --report lcov
sudo apt-get install lcov
lcov --remove lcov.info 'test/*' 'script/*' 'library/*' '**/libraries/**' > lcov2.info
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: lcov2.info
flags: solidity
fail_ci_if_error: true
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,6 @@ lcov.info


vendor/**
scripts/download_buf.sh
scripts/download_buf.sh

cache/
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[submodule "contracts/evm/xcall/lib/forge-std"]
path = contracts/evm/lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "contracts/evm/xcall/lib/openzeppelin-contracts-upgradeable"]
path = contracts/evm/lib/openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
[submodule "contracts/evm/xcall/lib/openzeppelin-contracts"]
path = contracts/evm/lib/openzeppelin-contracts
url = https://github.com/Openzeppelin/openzeppelin-contracts
23 changes: 23 additions & 0 deletions contracts/evm/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
PRIVATE_KEY=""
OWNER_ADDRESS=

PROTOCOL_FEE=0

# BINANCE TESTNET NETWORK SETUP
BINANCE_TESTNET_RPC_URL=http://127.0.0.1:9545/
BSC_NID=*
BSC_SCAN_API_KEY=

# BMC ADDRESS FOR ICON BERLIN TESTNET
ICON_NID=*
BMC_ADDRESS="cx000"


# BINANCE MAINNET NETWORK SETUP
BINANCE_MAINNET_RPC_URL=http://127.0.0.1:9545/
BSC_NID=*
BSC_SCAN_API_KEY=

# BMC ADDRESS FOR ICON MAINNET
ICON_NID=*
BMC_ADDRESS="cx000"
Empty file removed contracts/evm/.gitkeep
Empty file.
149 changes: 149 additions & 0 deletions contracts/evm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
## Foundry

**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.**

Foundry consists of:

- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools).
- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network.
- **Chisel**: Fast, utilitarian, and verbose solidity REPL.

## Documentation

https://book.getfoundry.sh/

## Usage

### Build

```shell
$ forge build
```

### Test


```shell
$ forge test -vv
```

To learn more about logs and traces, check out the documentation [here](https://book.getfoundry.sh/forge/tests?highlight=-vv#logs-and-traces).

To view all of the supported logging methods, check out the documentation [here](https://book.getfoundry.sh/reference/ds-test#logging).

### Gas Snapshots

```shell
$ forge snapshot
```

### Anvil
You can start the local EVM test network at any time:

```shell
$ anvil
```

### Deploy

```shell
export PRIVATE_KEY=<your-private-key>

$ forge script script/CallService.s.sol:CallServiceScript --rpc-url <your_rpc_url> --private-key <your_private_key>

For Example: (deploying the contract on localnet)
$ forge script script/CallService.s.sol:CallServiceScript --fork-url http://localhost:8545 \
--private-key $PRIVATE_KEY --broadcast

```


### Cast
Set the CONTRACT_ADDRESS variable in your terminal:

```sh
export CONTRACT_ADDRESS=<your-contract-address>
```

Call initialize on the contract

```sh
cast send $CONTRACT_ADDRESS "initialize(string)" "ENTER Chain NID HERE" --private-key $PRIVATE_KEY
```

We can then use cast to interact with it.

For read operations, we can use cast call: For Example:

```sh
cast call $CONTRACT_ADDRESS "admin()(address)"
```

For transactions, we can use cast send, passing in a private key and any arguments:

```sh
cast send $CONTRACT_ADDRESS "setAdmin(address)" 0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc --private-key $PRIVATE_KEY
```

To test that the greeting has been updated, run the `call` command again:

```sh
cast call $CONTRACT_ADDRESS "admin()(address)"
```


## Installing packages

You can install packages using the `forge install` command.

To try this out, let's install OpenZeppelin Contracts, then we'll use them to create an ERC721 token:

> You may need to add and commit any changes to your code to `git` in order to run the install script.
```sh
forge install OpenZeppelin/openzeppelin-contracts
```

Next, create a file named `remappings.txt` in the root of the project and add the following configuration:

```
@openzeppelin/=lib/openzeppelin-contracts/
```

This will allow us to easily import with the following syntax:

```solidity
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
```

You can view all of the automatically inferred remappings for the project by running the following command:

```sh
forge remappings
```


### Test coverage

You can check for test coverage by running the `coverage` command:

```sh
forge coverage
```

To debug in more details what has not been covered, use the `debug` report:

```sh
forge coverage --report debug
```



### Help

```shell
$ forge --help
$ anvil --help
$ cast --help
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.8.0;
pragma abicoder v2;

import "openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol";

contract LayerZeroAdapter is Initializable {
}
8 changes: 8 additions & 0 deletions contracts/evm/contracts/adapters/wormhole/WormholeAdapter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.8.0;
pragma abicoder v2;

import "openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol";

contract WormholeAdapter is Initializable {
}
Loading

0 comments on commit 6779754

Please sign in to comment.