Skip to content

Commit

Permalink
Proper deposit closing method implemented.
Browse files Browse the repository at this point in the history
  • Loading branch information
scx1332 authored Mar 14, 2024
1 parent 041ee9b commit d1cadd1
Show file tree
Hide file tree
Showing 14 changed files with 550 additions and 179 deletions.
80 changes: 0 additions & 80 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,86 +187,6 @@ jobs:
- name: Run tests (docker_03_problems)
run: cargo test --test docker_03_problems --profile=release-fast -- --test-threads=10

test_faucet:
name: Test Goerli faucet
timeout-minutes: 20

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Cache dependencies
uses: Swatinem/rust-cache@v2
with:
shared-key: "dev-build-cache"

- name: Build
run: cargo build

- name: Run tests (faucet)
run: cargo run -- generate-key -n 1 > .env

- name: Check if balance is 0
run: |
[ $(cargo run -- balance -c goerli | jq -r '.[] | .gasDecimal') == "0" ]
[ $(cargo run -- balance -c goerli | jq -r '.[] | .tokenDecimal') == "0" ]
env:
GOERLI_GETH_ADDR: ${{ secrets.GOERLI_RPC_ADDRESS }}

- name: Get ETH from faucet
run: cargo run -- get-dev-eth -c goerli
env:
GOERLI_GETH_ADDR: ${{ secrets.GOERLI_RPC_ADDRESS }}

- name: Check ETH balance after getting funds from faucet (should be 0.01)
run: |
sleep 60 # give time for the blockchain to propagate info about the transaction
[ $(cargo run -- balance -c goerli | jq -r '.[] | .gasDecimal') == "0.01" ]
env:
GOERLI_GETH_ADDR: ${{ secrets.GOERLI_RPC_ADDRESS }}

- name: Mint tokens
run: |
cargo run -- mint-test-tokens -c goerli
cargo run -- run
env:
GOERLI_GETH_ADDR: ${{ secrets.GOERLI_RPC_ADDRESS }}

- name: Check token balance
run: |
[ $(cargo run -- balance -c goerli | jq -r '.[] | .tokenDecimal') == "1000" ]
env:
GOERLI_GETH_ADDR: ${{ secrets.GOERLI_RPC_ADDRESS }}

- name: Transfer 166.6 GLM tokens
run: |
cargo run -- transfer -c goerli --recipient 0x5b984629E2Cc7570cBa7dD745b83c3dD23Ba6d0f --token glm --amount 166.6
cargo run -- run
env:
GOERLI_GETH_ADDR: ${{ secrets.GOERLI_RPC_ADDRESS }}

- name: Transfer all GLM tokens
run: |
cargo run -- transfer -c goerli --recipient 0x5b984629E2Cc7570cBa7dD745b83c3dD23Ba6d0f --token glm --all
cargo run -- run
env:
GOERLI_GETH_ADDR: ${{ secrets.GOERLI_RPC_ADDRESS }}

- name: Check token balance zero
run: |
[ $(cargo run -- balance -c goerli | jq -r '.[] | .tokenDecimal') == "0" ]
env:
GOERLI_GETH_ADDR: ${{ secrets.GOERLI_RPC_ADDRESS }}

- name: Transfer all left ETH tokens
run: |
cargo run -- transfer -c goerli --recipient 0x5b984629E2Cc7570cBa7dD745b83c3dD23Ba6d0f --token eth --all
cargo run -- run
env:
GOERLI_GETH_ADDR: ${{ secrets.GOERLI_RPC_ADDRESS }}

test_faucet_holesky:
name: Test Holesky faucet
timeout-minutes: 20
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deposit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ jobs:
erc20_processor run
erc20_processor balance
- name: Free deposit
- name: Close deposit
run: |
set -x
erc20_processor deposit close --deposit-id $DEPOSIT_ID0 --account-no 2
Expand Down
120 changes: 120 additions & 0 deletions .github/workflows/deposit2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
name: Deposit tests 2

on:
push:
workflow_dispatch:
schedule:
- cron: "42 3 * * *"

jobs:
test_deposit:
name: Test Deposit 2
timeout-minutes: 20

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Cache dependencies
uses: Swatinem/rust-cache@v2
with:
shared-key: "dev-build-cache"

- name: Build
run: |
cargo build
cp target/debug/erc20_processor /usr/local/bin/erc20_processor
[ $(which erc20_processor) == "/usr/local/bin/erc20_processor" ]
- name: Generate ethereum accounts
run: |
erc20_processor generate-key -n 5 > .env
cat .env | grep ETH_ADDRESS | sed "s/#\s//g" | sed "s/:\s/=/g" > $GITHUB_ENV
- name: Create random deposit id
run: |
echo DEPOSIT_NONCE0=$(shuf -i 0-2000000000000000000 -n 1) >> $GITHUB_ENV
echo DEPOSIT_NONCE1=$(shuf -i 0-2000000000000000000 -n 1) >> $GITHUB_ENV
echo DEPOSIT_NONCE2=$(shuf -i 0-2000000000000000000 -n 1) >> $GITHUB_ENV
- name: Show created addresses
run: |
echo "Eth address 0: $ETH_ADDRESS_0"
echo "Eth address 1: $ETH_ADDRESS_1"
echo "Eth address 2: $ETH_ADDRESS_2"
echo "Eth address 3: $ETH_ADDRESS_3"
echo "Eth address 4: $ETH_ADDRESS_4"
- name: Get ETH from faucet for account 1 and 2
run: |
erc20_processor get-dev-eth --account-no 1
erc20_processor get-dev-eth --account-no 2
- name: Check ETH balance after getting funds from faucet (should be 0.01)
run: |
x=1; while [ $(erc20_processor balance | jq -r ".\"$ETH_ADDRESS_1\".gasDecimal") != "0.01" ]; do echo "Waiting for funds for $x seconds"; sleep 5; x=$(( x + 5 )); done
while [ $(erc20_processor balance | jq -r ".\"$ETH_ADDRESS_2\".gasDecimal") != "0.01" ]; do echo "Waiting for funds for $x seconds"; sleep 5; x=$(( x + 5 )); done
- name: Mint tokens
run: |
erc20_processor mint-test-tokens --account-no 1
erc20_processor run
- name: Check token balance
run: |
[ $(erc20_processor balance | jq -r ".\"$ETH_ADDRESS_1\".tokenDecimal") == "1000" ]
- name: Create deposit
run: |
set -x
erc20_processor deposit create --account-no 1 --amount 1 --fee-amount 0.1 --block-for 0 --spender $ETH_ADDRESS_2 --deposit-nonce $DEPOSIT_NONCE0
erc20_processor deposit create --account-no 1 --amount 1 --fee-amount 0.1 --block-for 1000 --spender $ETH_ADDRESS_2 --deposit-nonce $DEPOSIT_NONCE1
erc20_processor run
- name: Get Deposit ID from funder and nonce id
run: |
echo DEPOSIT_ID0=$(erc20_processor deposit check --deposit-nonce $DEPOSIT_NONCE0 --deposit-funder=$ETH_ADDRESS_1 | jq -r ".depositId") >> $GITHUB_ENV
echo DEPOSIT_ID1=$(erc20_processor deposit check --deposit-nonce $DEPOSIT_NONCE1 --deposit-funder=$ETH_ADDRESS_1 | jq -r ".depositId") >> $GITHUB_ENV
- name: Make single transfer from deposit
run: |
set -x
erc20_processor transfer --deposit-id $DEPOSIT_ID0 --account-no 2 --amount 0.0001 --recipient $ETH_ADDRESS_4
erc20_processor run
- name: Make single transfer without deposit
run: |
set -x
erc20_processor run
- name: Make multiple transfers from deposit
run: |
set -x
erc20_processor transfer --account-no 1 --amount 0.0001 --recipient $ETH_ADDRESS_4
erc20_processor transfer --deposit-id $DEPOSIT_ID1 --account-no 2 --amount 0.000134 --recipient $ETH_ADDRESS_0
erc20_processor transfer --deposit-id $DEPOSIT_ID1 --account-no 2 --amount 0.0001632 --recipient $ETH_ADDRESS_3
erc20_processor transfer --deposit-id $DEPOSIT_ID1 --account-no 2 --amount 0.0001724 --recipient $ETH_ADDRESS_4
erc20_processor transfer --deposit-id $DEPOSIT_ID1 --account-no 2 --amount 0.000163 --recipient random
erc20_processor transfer --deposit-id $DEPOSIT_ID1 --account-no 2 --amount 0.0001235 --recipient random
erc20_processor transfer --deposit-id $DEPOSIT_ID1 --account-no 2 --amount 0.0001634 --recipient random
erc20_processor transfer --deposit-id $DEPOSIT_ID1 --account-no 2 --amount 0.000173 --recipient random
erc20_processor transfer --deposit-id $DEPOSIT_ID1 --account-no 2 --amount 0.0001346 --recipient random
erc20_processor transfer --deposit-id $DEPOSIT_ID1 --account-no 2 --amount 0.0001346 --recipient random
erc20_processor transfer --deposit-id $DEPOSIT_ID1 --account-no 2 --amount 0.000136 --recipient random
erc20_processor transfer --deposit-id $DEPOSIT_ID1 --account-no 2 --amount 0.000145 --recipient random
erc20_processor transfer --deposit-id $DEPOSIT_ID1 --account-no 2 --amount 0.00016 --recipient random
erc20_processor transfer --deposit-id $DEPOSIT_ID1 --account-no 2 --amount 0.000173 --recipient random
erc20_processor transfer --deposit-id $DEPOSIT_ID1 --account-no 2 --amount 0.000145 --recipient random
erc20_processor transfer --deposit-id $DEPOSIT_ID1 --account-no 2 --amount 0.000164 --recipient random
erc20_processor deposit close --deposit-id $DEPOSIT_ID0 --account-no 2
erc20_processor deposit close --deposit-id $DEPOSIT_ID1 --account-no 2
erc20_processor run
- name: Transfer all left ETH tokens
run: |
set -x
erc20_processor transfer --account-no 1 --recipient 0x5b984629E2Cc7570cBa7dD745b83c3dD23Ba6d0f --token eth --all
erc20_processor transfer --account-no 2 --recipient 0x5b984629E2Cc7570cBa7dD745b83c3dD23Ba6d0f --token eth --all
erc20_processor run
6 changes: 3 additions & 3 deletions crates/erc20_payment_lib/config-payments.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ https://rpc.ankr.com/eth_goerli,
priority = 0
max-timeout-ms = 5000
verify-interval-secs = 60
allowed-head-behind-secs = 60
allowed-head-behind-secs = 12000

[[chain.goerli.rpc-endpoints]]
priority = 0
max-timeout-ms = 5000
verify-interval-secs = 60
allowed-head-behind-secs = 120
allowed-head-behind-secs = 12000
dns-source = "goerli.rpc-node.dev.golem.network."


Expand All @@ -137,7 +137,7 @@ chain-name = "Holesky"
chain-id = 17000
currency-symbol = "tETH"
priority-fee = 0.000001
max-fee-per-gas = 10.0
max-fee-per-gas = 20.0
transaction-timeout = 100
token = { address = "0x8888888815bf4DB87e57B609A50f938311EEd068", symbol = "tGLM" }
multi-contract = { address = "0xAaAAAaA00E1841A63342db7188abA84BDeE236c7", max-at-once = 10 }
Expand Down
23 changes: 23 additions & 0 deletions crates/erc20_payment_lib/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,17 @@ pub fn encode_deposit_transfer(
)
}

pub fn encode_deposit_transfer_and_close(
deposit_id: U256,
packed: Vec<[u8; 32]>,
) -> Result<Vec<u8>, web3::ethabi::Error> {
contract_encode(
&LOCK_CONTRACT_TEMPLATE,
"depositTransferAndClose",
(deposit_id, packed),
)
}

pub fn encode_multi_direct(
recipients: Vec<Address>,
amounts: Vec<U256>,
Expand Down Expand Up @@ -180,6 +191,18 @@ pub fn encode_payout_single(
)
}

pub fn encode_payout_single_and_close(
id: U256,
recipient: Address,
amount: U256,
) -> Result<Vec<u8>, web3::ethabi::Error> {
contract_encode(
&LOCK_CONTRACT_TEMPLATE,
"depositSingleTransferAndClose",
(id, recipient, amount),
)
}

pub fn encode_get_deposit_details(id: U256) -> Result<Vec<u8>, web3::ethabi::Error> {
contract_encode(&LOCK_CONTRACT_TEMPLATE, "getDeposit", (id,))
}
Loading

0 comments on commit d1cadd1

Please sign in to comment.