Skip to content

Commit

Permalink
prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
kumaryash90 committed Feb 13, 2024
1 parent 6804ea6 commit 98c5556
Show file tree
Hide file tree
Showing 10 changed files with 481 additions and 378 deletions.
22 changes: 22 additions & 0 deletions .github/composite-actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: "Install"
description: "Sets up Node.js and runs install"

runs:
using: composite
steps:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18
registry-url: "https://registry.npmjs.org"
cache: "yarn"

- name: Install dependencies
shell: bash
run: yarn

- name: Setup lcov
shell: bash
run: |
sudo apt update
sudo apt install -y lcov
36 changes: 36 additions & 0 deletions .github/workflows/prettier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This is a basic workflow to help you get started with Actions

name: Prettier Formatting

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [main]
pull_request:
branches: [main]

# cancel previous runs if new commits are pushed to the branch
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
# This workflow contains a single job called "build"
lint:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive
fetch-depth: 25

- name: Setup Project
uses: ./.github/composite-actions/setup

- name: Run Prettier
run: yarn prettier:contracts
34 changes: 0 additions & 34 deletions .github/workflows/test.yml

This file was deleted.

52 changes: 52 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# This is a basic workflow to help you get started with Actions

name: Tests

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [main]
pull_request:
branches: [main]

# cancel previous runs if new commits are pushed to the branch
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
test:
# The type of runner that the job will run on
# 16 core paid runner
runs-on: ubuntu-latest-16

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive
fetch-depth: 25
node-version: 18

- name: Setup Project
uses: ./.github/composite-actions/setup

- name: Install Foundry
uses: onbjerg/foundry-toolchain@v1
with:
version: nightly
- name: Run coverage and tests
run: |
forge coverage --report lcov
lcov --remove lcov.info -o lcov.info 'src/test/**'
lcov --remove lcov.info -o lcov.info 'contracts/external-deps/**'
lcov --remove lcov.info -o lcov.info 'contracts/eip/**'
forge test
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
files: ./lcov.info,
18 changes: 18 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"arrowParens": "avoid",
"bracketSpacing": true,
"endOfLine":"auto",
"printWidth": 120,
"useTabs": false,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "all",
"overrides": [
{
"files": "*.sol",
"options": {
"tabWidth": 4
}
}
]
}
103 changes: 47 additions & 56 deletions contracts/MockTarget.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,67 +5,58 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "lib/forge-std/src/console.sol";

contract MockTarget {
event TargetLog(
address sender,
address receiver,
address tokenAddress,
uint256 tokenAmount,
string message
);
event TargetLog(address sender, address receiver, address tokenAddress, uint256 tokenAmount, string message);

address constant private NATIVE_TOKEN_ADDRESS = 0x0000000000000000000000000000000000000000;
address private constant NATIVE_TOKEN_ADDRESS = 0x0000000000000000000000000000000000000000;

function decodeData(bytes memory data) private pure returns (address, address, address, uint256, string memory) {
return abi.decode(data, (address, address, address, uint256, string));
}

function performERC20Action(
address sender,
address payable receiver,
address tokenAddress,
uint256 tokenAmount,
string memory message
) private {
emit TargetLog(sender, receiver, tokenAddress, tokenAmount, message);
console.log(
"Transferring %s erc20 tokens from %s to %s", tokenAmount, sender, receiver
);

require(IERC20(tokenAddress).transferFrom(msg.sender, receiver, tokenAmount), "Token transfer failed");
}

function performNativeTokenAction(
address sender,
address payable receiver,
address tokenAddress,
uint256 tokenAmount,
string memory message
) private {
emit TargetLog(sender, receiver, tokenAddress, tokenAmount, message);
console.log(
"Transferring %s native tokens from %s to %s", tokenAmount, sender, receiver
);
(bool sent, ) = receiver.call{value: msg.value}("");
require(sent, "Failed to send Ether");
}
function decodeData(bytes memory data) private pure returns (address, address, address, uint256, string memory) {
return abi.decode(data, (address, address, address, uint256, string));
}

fallback() external payable {
require(msg.data.length > 0, "data required");
(address sender, address receiver,
address tokenAddress, uint256 tokenAmount,
string memory message
) = decodeData(msg.data);
function performERC20Action(
address sender,
address payable receiver,
address tokenAddress,
uint256 tokenAmount,
string memory message
) private {
emit TargetLog(sender, receiver, tokenAddress, tokenAmount, message);
console.log("Transferring %s erc20 tokens from %s to %s", tokenAmount, sender, receiver);

require(IERC20(tokenAddress).transferFrom(msg.sender, receiver, tokenAmount), "Token transfer failed");
}

if(tokenAddress == NATIVE_TOKEN_ADDRESS)
{
console.log("Calling native token action!");
performNativeTokenAction(payable(sender), payable(receiver), tokenAddress, tokenAmount, message);
function performNativeTokenAction(
address sender,
address payable receiver,
address tokenAddress,
uint256 tokenAmount,
string memory message
) private {
emit TargetLog(sender, receiver, tokenAddress, tokenAmount, message);
console.log("Transferring %s native tokens from %s to %s", tokenAmount, sender, receiver);
(bool sent, ) = receiver.call{ value: msg.value }("");
require(sent, "Failed to send Ether");
}
else {
console.log("Calling erc20 token action!");
performERC20Action(payable(sender), payable(receiver), tokenAddress, tokenAmount, message);

fallback() external payable {
require(msg.data.length > 0, "data required");
(
address sender,
address receiver,
address tokenAddress,
uint256 tokenAmount,
string memory message
) = decodeData(msg.data);

if (tokenAddress == NATIVE_TOKEN_ADDRESS) {
console.log("Calling native token action!");
performNativeTokenAction(payable(sender), payable(receiver), tokenAddress, tokenAmount, message);
} else {
console.log("Calling erc20 token action!");
performERC20Action(payable(sender), payable(receiver), tokenAddress, tokenAmount, message);
}
}
}

receive() external payable {}
receive() external payable {}
}
Loading

0 comments on commit 98c5556

Please sign in to comment.