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

Run e2e tests on alfajores #258

Merged
merged 23 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
15 changes: 13 additions & 2 deletions e2e_test/js-tests/send_tx.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,29 @@ const devChain = defineChain({
},
});

var chain;
switch(process.env.NETWORK) {
case "alfajores":
chain = celoAlfajores;
break;
default:
chain = devChain;
// Code to run if no cases match
};

const account = privateKeyToAccount(privateKey);

const publicClient = createPublicClient({
account,
chain: devChain,
chain: chain,
transport: http(),
});
const walletClient = createWalletClient({
account,
chain: devChain,
chain: chain,
transport: http(),
});

function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
Expand Down
13 changes: 11 additions & 2 deletions e2e_test/js-tests/test_viem_tx.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,24 @@ const devChain = defineChain({
},
});

const chain = (() => {
switch (process.env.NETWORK) {
case 'alfajores':
return celoAlfajores
default:
return devChain
};
})();

// Set up clients/wallet
const publicClient = createPublicClient({
chain: devChain,
chain: chain,
transport: http(),
});
const account = privateKeyToAccount(process.env.ACC_PRIVKEY);
const walletClient = createWalletClient({
account,
chain: devChain,
chain: chain,
transport: http(),
});

Expand Down
44 changes: 27 additions & 17 deletions e2e_test/run_all_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,25 @@ source "$SCRIPT_DIR/shared.sh"

TEST_GLOB=$1

## Start geth
cd "$SCRIPT_DIR/.." || exit 1
make geth
trap 'kill %%' EXIT # kill bg job at exit
build/bin/geth --dev --http --http.api eth,web3,net --txpool.nolocals &>"$SCRIPT_DIR/geth.log" &

# Wait for geth to be ready
for _ in {1..10}; do
if cast block &>/dev/null; then
break
fi
sleep 0.2
done

## Run tests
echo Geth ready, start tests
cd "$SCRIPT_DIR" || exit 1
if [ -z $NETWORK ]; then
## Start geth
cd "$SCRIPT_DIR/.." || exit 1
make geth
trap 'kill %%' EXIT # kill bg job at exit
build/bin/geth --dev --http --http.api eth,web3,net --txpool.nolocals &>"$SCRIPT_DIR/geth.log" &

# Wait for geth to be ready
for _ in {1..10}; do
if cast block &>/dev/null; then
break
fi
sleep 0.2
done

## Run tests
echo Geth ready, start tests
cd "$SCRIPT_DIR" || exit 1
fi

# There's a problem with geth return errors on the first transaction sent.
# See https://github.com/ethereum/web3.py/issues/3212
Expand All @@ -32,6 +34,14 @@ cast send --async --json --private-key "$ACC_PRIVKEY" "$TOKEN_ADDR" 'transfer(ad
failures=0
tests=0
for f in test_*"$TEST_GLOB"*; do
if [[ -n $NETWORK ]]; then
case $f in
# Skip tests that require a local network.
test_fee_currency_fails_on_credit.sh|test_fee_currency_fails_on_debit.sh|test_fee_currency_fails_intrinsic.sh)
karlb marked this conversation as resolved.
Show resolved Hide resolved
continue
;;
esac
fi
echo -e "\nRun $f"
if "./$f"; then
tput setaf 2 || true
Expand Down
23 changes: 18 additions & 5 deletions e2e_test/shared.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,29 @@

SCRIPT_DIR=$(readlink -f "$(dirname "$0")")
export SCRIPT_DIR
export ETH_RPC_URL=http://127.0.0.1:8545

case $NETWORK in
alfajores)
export ETH_RPC_URL=https://alfajores-forno.celo-testnet.org
export TOKEN_ADDR=0xF194afDf50B03e69Bd7D057c1Aa9e10c9954E4C9
export FEE_HANDLER=0xEAaFf71AB67B5d0eF34ba62Ea06Ac3d3E2dAAA38
export FEE_CURRENCY=0x4822e58de6f5e485eF90df51C41CE01721331dC0
echo "Using Alfajores network"
;;
'')
export ETH_RPC_URL=http://127.0.0.1:8545
export TOKEN_ADDR=0x471ece3750da237f93b8e339c536989b8978a438
export FEE_HANDLER=0xcd437749e43a154c07f3553504c68fbfd56b8778
export FEE_CURRENCY=0x000000000000000000000000000000000000ce16
export FEE_CURRENCY2=0x000000000000000000000000000000000000ce17
echo "Using local network"
;;
esac

export ACC_ADDR=0x42cf1bbc38BaAA3c4898ce8790e21eD2738c6A4a
export ACC_PRIVKEY=0x2771aff413cac48d9f8c114fabddd9195a2129f3c2c436caa07e27bb7f58ead5
export REGISTRY_ADDR=0x000000000000000000000000000000000000ce10
export TOKEN_ADDR=0x471ece3750da237f93b8e339c536989b8978a438
export FEE_CURRENCY_DIRECTORY_ADDR=0x9212Fb72ae65367A7c887eC4Ad9bE310BAC611BF
export FEE_CURRENCY=0x000000000000000000000000000000000000ce16
export FEE_CURRENCY2=0x000000000000000000000000000000000000ce17
export FEE_HANDLER=0xcd437749e43a154c07f3553504c68fbfd56b8778
export ORACLE3=0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0003

export FIXIDITY_1=1000000000000000000000000
Expand Down