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

Repairing E2E tests #154

Merged
merged 20 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
32 changes: 30 additions & 2 deletions .github/workflows/testnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ on:
# This cron expression triggers the workflow at 8:00 UTC every day
- cron: "8 0 * * *"
# uncomment to debug in a PR
#pull_request:
# pull_request:

jobs:
build-and-deploy:
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -22,6 +24,27 @@ jobs:
rustup default 1.81.0
rustup update
- run: cargo version

- uses: actions/setup-java@v3
with:
distribution: "temurin" # See 'Supported distributions' for available options
java-version: "19"

- name: Install apalache for e2e
run: |
gh release download --repo apalache-mc/apalache --pattern apalache.tgz
tar -xvzf apalache.tgz --directory . > /dev/null
# add apalache-mc to the path, this is a GitHub idiom
echo "`pwd`/apalache/bin" >> $GITHUB_PATH
konnov marked this conversation as resolved.
Show resolved Hide resolved

- name: Install solarkraft for e2e
run: |
cd solarkraft
npm install --dev
thpani marked this conversation as resolved.
Show resolved Hide resolved
npm run compile
npm link

# install stellar
- uses: stellar/stellar-cli@main
with:
version: 22.0.0
Expand Down Expand Up @@ -59,4 +82,9 @@ jobs:
- name: Deploy xycloans
run: |
cd ContractExamples
./scripts/xycloans-populate.sh
./scripts/xycloans-populate.sh

- name: End-to-end tests
run: |
cd solarkraft
npm run e2e
9 changes: 8 additions & 1 deletion ContractExamples/scripts/alert-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ set -e
dir=$(cd `dirname $0`; pwd -P)
cd ${dir}/..

# the location of the hardcoded data to generate
HARDCODED="${dir}/../../solarkraft/test/e2e/generated/alertHardcoded.ts"
echo "// AUTO-GENERATED by alert-deploy.sh" > $HARDCODED

NET=testnet
(stellar network ls | grep -q $NET) || (echo "add testnet via stellar network"; exit 1)

Expand All @@ -25,4 +29,7 @@ set -x
./scripts/build.sh

stellar contract deploy --wasm target/wasm32-unknown-unknown/release/alert.wasm \
--source $ACCOUNT --network $NET
--source $ACCOUNT --network $NET | tee >.alert.id

CONTRACT_ADDR=`head -n 1 .alert.id`
echo "export const ALERT_CONTRACT_ADDR = \"$CONTRACT_ADDR\"" >> $HARDCODED
51 changes: 32 additions & 19 deletions ContractExamples/scripts/setter-populate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ dir=$(cd `dirname $0`; pwd -P)

cd ${dir}/..

# the location of the hardcoded data to generate
HARDCODED="${dir}/../../solarkraft/test/e2e/generated/setterHardcoded.ts"
echo "// AUTO-GENERATED by setter-populate.sh" > $HARDCODED

NET=testnet
(stellar network ls | grep -q $NET) || (echo "add testnet via stellar network"; exit 1)

Expand All @@ -27,43 +31,52 @@ set -x

./scripts/build.sh

HEIGHT=`curl -s https://horizon-testnet.stellar.org/ | jq .history_latest_ledger`
echo "export const SETTER_HEIGHT = $HEIGHT" >> $HARDCODED

stellar contract deploy --wasm target/wasm32-unknown-unknown/release/setter.wasm \
--source $ACCOUNT --network $NET | tee >.setter.id
--source $ACCOUNT --network $NET 2>.setter.err | tee >.setter.id
grep "wasm hash" err | sed 's/.*hash \([0-9a-f]*\)/\1/' > .setter.hash

CONTRACT_ADDR=`head -n 1 .setter.id`
WASM_HASH=`head -n 1 .setter.hash`
echo "export const SETTER_CONTRACT_ADDR = \"$CONTRACT_ADDR\"" >> $HARDCODED
echo "export const SETTER_WASM_HASH = \"$WASM_HASH\"" >> $HARDCODED

stellar contract invoke --id $(cat .setter.id) --source $ACCOUNT --network $NET \
stellar contract invoke --id ${CONTRACT_ADDR} --source $ACCOUNT --network $NET \
-- set_bool --v true
stellar contract invoke --id $(cat .setter.id) --source $ACCOUNT --network $NET \
stellar contract invoke --id ${CONTRACT_ADDR} --source $ACCOUNT --network $NET \
-- set_u32 --v 42
stellar contract invoke --id $(cat .setter.id) --source $ACCOUNT --network $NET \
stellar contract invoke --id ${CONTRACT_ADDR} --source $ACCOUNT --network $NET \
-- set_i32 --v '-42'
stellar contract invoke --id $(cat .setter.id) --source $ACCOUNT --network $NET \
stellar contract invoke --id ${CONTRACT_ADDR} --source $ACCOUNT --network $NET \
-- set_u64 --v 42
stellar contract invoke --id $(cat .setter.id) --source $ACCOUNT --network $NET \
stellar contract invoke --id ${CONTRACT_ADDR} --source $ACCOUNT --network $NET \
-- set_i64 --v '-42'
stellar contract invoke --id $(cat .setter.id) --source $ACCOUNT --network $NET \
stellar contract invoke --id ${CONTRACT_ADDR} --source $ACCOUNT --network $NET \
-- set_u128 --v 42
stellar contract invoke --id $(cat .setter.id) --source $ACCOUNT --network $NET \
stellar contract invoke --id ${CONTRACT_ADDR} --source $ACCOUNT --network $NET \
-- set_i128 --v '-42'
stellar contract invoke --id $(cat .setter.id) --source $ACCOUNT --network $NET \
stellar contract invoke --id ${CONTRACT_ADDR} --source $ACCOUNT --network $NET \
-- set_sym --v hello
stellar contract invoke --id $(cat .setter.id) --source $ACCOUNT --network $NET \
stellar contract invoke --id ${CONTRACT_ADDR} --source $ACCOUNT --network $NET \
-- set_bytes --v beef
stellar contract invoke --id $(cat .setter.id) --source $ACCOUNT --network $NET \
stellar contract invoke --id ${CONTRACT_ADDR} --source $ACCOUNT --network $NET \
-- set_bytes32 --v beef0123456789beef0123456789beef0123456789ab
stellar contract invoke --id $(cat .setter.id) --source $ACCOUNT --network $NET \
stellar contract invoke --id ${CONTRACT_ADDR} --source $ACCOUNT --network $NET \
-- set_vec --v '[ 1, -2, 3 ]'
stellar contract invoke --id $(cat .setter.id) --source $ACCOUNT --network $NET \
stellar contract invoke --id ${CONTRACT_ADDR} --source $ACCOUNT --network $NET \
-- set_map --v '{ "2": 3, "4": 5 }'
stellar contract invoke --id $(cat .setter.id) --source $ACCOUNT --network $NET \
stellar contract invoke --id ${CONTRACT_ADDR} --source $ACCOUNT --network $NET \
-- set_address --v GDIY6AQQ75WMD4W46EYB7O6UYMHOCGQHLAQGQTKHDX4J2DYQCHVCR4W4
stellar contract invoke --id $(cat .setter.id) --source $ACCOUNT --network $NET \
stellar contract invoke --id ${CONTRACT_ADDR} --source $ACCOUNT --network $NET \
-- set_struct --v '{ "a": 1, "b": "-100" }'
stellar contract invoke --id $(cat .setter.id) --source $ACCOUNT --network $NET \
stellar contract invoke --id ${CONTRACT_ADDR} --source $ACCOUNT --network $NET \
-- set_enum --v '{ "B": "-200" }'
stellar contract invoke --id $(cat .setter.id) --source $ACCOUNT --network $NET \
stellar contract invoke --id ${CONTRACT_ADDR} --source $ACCOUNT --network $NET \
-- remove_bool

# NOTE: we do not do that in the CI script
# we can provoke a failed transaction by submitting 2 transactions in parallel from different accounts
#stellar contract invoke --id $(cat .setter.id) --source $ACCOUNT --network $NET -- set_bool_if_notset &
#stellar contract invoke --id $(cat .setter.id) --source $ACCOUNT2 --network $NET -- set_bool_if_notset
#stellar contract invoke --id ${CONTRACT_ADDR} --source $ACCOUNT --network $NET -- set_bool_if_notset &
#stellar contract invoke --id ${CONTRACT_ADDR} --source $ACCOUNT2 --network $NET -- set_bool_if_notset
1 change: 1 addition & 0 deletions solarkraft/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18.20.5
34 changes: 2 additions & 32 deletions solarkraft/package-lock.json

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

32 changes: 25 additions & 7 deletions solarkraft/test/e2e/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,26 @@ import { describe, it } from 'mocha'

import { spawn } from 'nexpect'

import {
SETTER_CONTRACT_ADDR,
SETTER_HEIGHT,
} from './generated/setterHardcoded.js'

// Tests against the last tx of the deployed setter contract

describe('fetch', () => {
it('fails to fetch when provided typemap does not exist', function (done) {
this.timeout(50000)
spawn(
'solarkraft fetch --typemap bogusFile --rpc https://horizon-testnet.stellar.org --id CA6DAY7MPOKVL5BB3CVKMAPX3UGFURQCNLTT4DPPF6MDNA3RSERQZ55Y --height 9391 --timeout 10'
'solarkraft',
[
'fetch',
'--typemap=bogusFile',
`--id=${SETTER_CONTRACT_ADDR}`,
`--height=${SETTER_HEIGHT}`,
'--timeout=10',
],
{ verbose: false }
)
.wait('The typemap file bogusFile does not exist.')
.wait('[Error]')
Expand All @@ -20,13 +33,18 @@ describe('fetch', () => {
it('fetches transactions', function (done) {
this.timeout(50000)
spawn(
'solarkraft fetch --rpc https://horizon-testnet.stellar.org --id CD4MXYZJKHXHEP7YK72L6K4Y6ANFVSXSTI3VPJXV5M4QFGF5PGH5PDDJ --height 96034 --timeout 10'
'solarkraft',
[
'fetch',
`--id=${SETTER_CONTRACT_ADDR}`,
`--height=${SETTER_HEIGHT}`,
'--timeout=10',
],
{ verbose: false }
)
.wait(
'Target contract: CD4MXYZJKHXHEP7YK72L6K4Y6ANFVSXSTI3VPJXV5M4QFGF5PGH5PDDJ'
)
.wait('Fetching the ledger for 96034')
.wait('+ save: 96035')
.wait(`Target contract: ${SETTER_CONTRACT_ADDR}...`)
.wait(`Fetching the ledger for ${SETTER_HEIGHT}`)
.wait(/\+ save: \d+/)
.run(done)
})
})
3 changes: 3 additions & 0 deletions solarkraft/test/e2e/generated/alertHardcoded.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// AUTO-GENERATED by alert-deploy.sh
export const ALERT_CONTRACT_ADDR =
'CCU7KC7WCEW3AWPOFZ4GHTJSESB3N2AIZXD4YPDWUKT67J6HSNTL4PZC'
6 changes: 6 additions & 0 deletions solarkraft/test/e2e/generated/setterHardcoded.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// AUTO-GENERATED by setter-populate.sh
export const SETTER_HEIGHT = 102428
export const SETTER_CONTRACT_ADDR =
'CATRQFD3OSJNNKES4W4PZOGS34C324WTHV63ZCJBGQVUE7WR74NGCMNZ'
export const SETTER_WASM_HASH =
'9175f9ecd34de878d195e3ae9c45466a4e6342e9c0b8d8f4358e13e4a92f1d28'
29 changes: 20 additions & 9 deletions solarkraft/test/e2e/invokeAlert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import { invokeAlert } from '../../src/verifier/invokeAlert.js'
import { Keypair, Networks } from '@stellar/stellar-sdk'
import { VerificationStatus } from '../../src/fetcher/storage.js'

// hard-coded contract id that has to be changed,
// when the Setter contract is redeployed via alert-deploy.sh
const CONTRACT_ID = 'CDRCCMLPCAKOZSEECX7EEXIPNPU32JGEKG3QMHKM7ZNO5IRBUE66DQ6O'
import { ALERT_CONTRACT_ADDR } from './generated/alertHardcoded.js'

// const LocalRPC = 'https://localhost:8000/'
const TestnetRPC = 'https://soroban-testnet.stellar.org:443'

Expand All @@ -34,7 +33,7 @@ describe('alert contract invocation', () => {
TestnetRPC,
sourceKeypair,
Networks.TESTNET,
CONTRACT_ID,
ALERT_CONTRACT_ADDR,
txHash,
VerificationStatus.NoViolation
)
Expand All @@ -45,18 +44,30 @@ describe('alert contract invocation', () => {
it('errors on bogus alert id', function (done) {
this.timeout(50000)
spawn(
'solarkraft verify --home test/e2e/tla/ --txHash 406d278860b5531dd1443532f3457c5daa288e8eb0007d2a8e2aa0127e87949e --monitor test/e2e/tla/setter_mon.tla --alert bogus'
'solarkraft',
[
'verify',
'--home=./test/e2e/tla/',
'--txHash=406d278860b5531dd1443532f3457c5daa288e8eb0007d2a8e2aa0127e87949e',
'--monitor=./test/e2e/tla/setter_mon.tla',
'--alert=bogus',
],
{ verbose: true }
)
.wait('Invalid contract ID: bogus')
.expect('No alert submitted.')
.run(done)
})

it('alerts the contrat when specified', function (done) {
it('alerts the contract when specified', function (done) {
this.timeout(50000)
spawn(
`solarkraft verify --home test/e2e/tla/ --txHash 406d278860b5531dd1443532f3457c5daa288e8eb0007d2a8e2aa0127e87949e --monitor test/e2e/tla/setter_mon.tla --alert ${CONTRACT_ID}`
)
spawn('solarkraft', [
'verify',
'--home=test/e2e/tla/',
'--txHash=406d278860b5531dd1443532f3457c5daa288e8eb0007d2a8e2aa0127e87949e',
'--monitor=test/e2e/tla/setter_mon.tla',
`--alert=${ALERT_CONTRACT_ADDR}`,
])
.wait('Preparing to submit alert.')
.wait('Transaction successful')
.run(done)
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading