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

feat(test): adding JS tests to the CI #284

Merged
merged 46 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
7a54233
ci: adding build to the ci along with sample js file
Sep 24, 2024
bd5ecfc
ci: changing the location of the bin
Sep 24, 2024
546c15b
ci: fixing again
Sep 24, 2024
2ff77fb
ci: fixing with location again
Sep 24, 2024
e6e0b19
ci: fixing ci with the path
Sep 24, 2024
bb2895f
ci: fixing try 5
Sep 24, 2024
63c1403
ci: fix 6
Sep 24, 2024
9076221
ci: fix 7
Sep 24, 2024
fb7f69c
ci: fix 8
Sep 24, 2024
59da248
ci: fix 9
Sep 24, 2024
c64ecb5
ci: fix 10
Sep 24, 2024
84f3d79
test: js test in working
Sep 25, 2024
2c4ff51
ci: updated for starknet js test
Sep 25, 2024
487cbf1
ci: looking for error in ci
Sep 25, 2024
65f6d19
ci: updating ci to make madara run in background
Sep 25, 2024
b4a7964
ci: adding tests directly where we run madara
Sep 25, 2024
cf66d68
ci: fixing the starknet js again
Sep 25, 2024
a559e43
ci: fixing 0
Sep 25, 2024
77ebc38
ci: fixing 1
Sep 25, 2024
b1f8045
ci: fixing 2
Sep 25, 2024
28911ff
ci: building cairo projects manually
Sep 25, 2024
3540f8f
ci: fixing again 4
Sep 25, 2024
7f282be
ci: trying to run tests atleast once
Sep 25, 2024
2818015
ci: fixing it again
Sep 25, 2024
5587604
ci: adding constand RPC_URL
Sep 25, 2024
bd82c3e
test: js test final cleanup
Sep 25, 2024
d48e9fa
test: ERC20 json removed
Sep 25, 2024
28ee4af
Delete js_tests/package-lock.json
Mohiiit Sep 25, 2024
79bc557
Merge branch 'main' into test/js-test
Mohiiit Sep 25, 2024
a78f731
ci: cache key updated, account deploy test updated, docs added
Sep 27, 2024
8b94b87
Merge branch 'main' into test/js-test
Mohiiit Sep 27, 2024
2374e7c
ci: trying triggering the ci
Sep 27, 2024
750f32a
ci: trying triggering the ci
Sep 27, 2024
1ad1310
linting
Sep 27, 2024
d982f44
ci: trying with different cache keys
Sep 27, 2024
f20630a
test: js_test moved under tests directory, changed workflow according…
Sep 30, 2024
fc1c4ab
test: updated the relative paths
Sep 30, 2024
8d936b9
linting
Sep 30, 2024
4e3b0f8
fix: trying syncing only 10 blocks for a test and restored the covera…
Sep 30, 2024
c649d6a
main merged
Oct 1, 2024
d6b3fd8
fix: fixing tests
Oct 1, 2024
2661e21
fix: fixing js test arguments and updating test a few blocks sync
Oct 1, 2024
d8eeafc
test: reduced devnet block time to 3 seconds
Oct 1, 2024
0e55b47
fix: fixing js tests by removing nonce
Oct 1, 2024
03dcf61
fix: js test fix:
Oct 1, 2024
a25dd48
Merge branch 'main' into test/js-test
Mohiiit Oct 3, 2024
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
42 changes: 42 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Task - Build Madara
on:
workflow_dispatch:
workflow_call:
jobs:
build:
permissions:
pull-requests: write
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
submodules: true
- uses: Swatinem/rust-cache@v2
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: 1.78.0
- name: Setup build deps
run: |
sudo apt-get update
sudo apt-get install -y clang llvm libudev-dev protobuf-compiler
- uses: rui314/setup-mold@v1
- uses: software-mansion/setup-scarb@v1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why you are calling 2 times software-mansion/setup-scarb@v1 for version 2.8.2?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my bad, removed

with:
scarb-version: "2.8.2"
- uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: Build
run: |
cargo build --release --bin madara
- name: Cache Madara binary
uses: actions/cache@v3
with:
path: target/release/madara
key: ${{ runner.os }}-madara-${{ hashFiles('Cargo.lock') }}
- name: Cache Cairo build artifacts
uses: actions/cache@v3
with:
path: cairo/target
key: ${{ runner.os }}-madara-${{ hashFiles('Scarb.lock') }}
11 changes: 10 additions & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
name: Workflow - Pull Request

on:
Expand Down Expand Up @@ -38,3 +37,13 @@ jobs:
uses: ./.github/workflows/coverage.yml
needs: changelog
secrets: inherit

build:
name: Build Madara
uses: ./.github/workflows/build.yml
needs: changelog

js_test:
name: Run JS Tests
uses: ./.github/workflows/starknet-js-test.yml
needs: build
32 changes: 32 additions & 0 deletions .github/workflows/starknet-js-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Starknet-js Compatibility Tests

on:
workflow_dispatch:
workflow_call:

jobs:
js-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Restore Madara binary
uses: actions/cache@v3
with:
path: target/release/madara
key: ${{ runner.os }}-madara-${{ hashFiles('Cargo.lock') }}
fail-on-cache-miss: true
- name: Restore Cairo build artifacts
uses: actions/cache@v3
with:
path: cairo/target
key: ${{ runner.os }}-madara-${{ hashFiles('Scarb.lock') }}
fail-on-cache-miss: true
- name: Setup dev chain and run tests
run: |
./target/release/madara --name madara --base-path ../madara3 --network devnet --authority --telemetry-disabled --rpc-port 9944 --rpc-cors "*" --rpc-external --devnet --preset test &
MADARA_PID=$!
while ! echo exit | nc localhost 9944; do sleep 1; done
cd tests/js_tests
npm install
npm test
kill $MADARA_PID
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next release

- test: Starknet-js basic tests added
- feat: move to karnot runner
- fix: docker file fixes for devnet
- fix(block-production): fix bouncer calculation and declared classes
Expand Down
1 change: 1 addition & 0 deletions cairo/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v

[[target.starknet-contract]]
sierra = true
casm = true

[scripts]
test = "snforge test"
25 changes: 25 additions & 0 deletions cairo/src/hello.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#[starknet::interface]
pub trait IHelloStarknet<TContractState> {
fn increase_balance(ref self: TContractState, amount: felt252);
fn get_balance(self: @TContractState) -> felt252;
}

#[starknet::contract]
mod HelloStarknet {
#[storage]
struct Storage {
balance: felt252,
}

#[abi(embed_v0)]
impl HelloStarknetImpl of super::IHelloStarknet<ContractState> {
fn increase_balance(ref self: ContractState, amount: felt252) {
assert(amount != 0, 'Amount cannot be 0');
self.balance.write(self.balance.read() + amount);
}

fn get_balance(self: @ContractState) -> felt252 {
self.balance.read()
}
}
}
1 change: 1 addition & 0 deletions cairo/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pub mod erc20;
pub mod udc;
pub mod account;
pub mod test_account;
pub mod hello;
2 changes: 1 addition & 1 deletion crates/primitives/chain_config/presets/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ versioned_constants:
"0.13.2": "crates/primitives/chain_config/resources/versioned_constants_13_2.json"
eth_core_contract_address: "0xE2Bb56ee936fd6433DC0F6e7e3b8365C906AA057"
latest_protocol_version: "0.13.2"
block_time: 360
block_time: 3
pending_block_update_time: 2
execution_batch_size: 16
bouncer_config:
Expand Down
10 changes: 5 additions & 5 deletions crates/tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,20 +224,20 @@ async fn madara_can_sync_a_few_blocks(_set_workdir: ()) {
"sepolia",
"--no-sync-polling",
"--n-blocks-to-sync",
"20",
"10",
"--no-l1-sync",
"--preset=sepolia",
])
.run();
node.wait_for_ready().await;
node.wait_for_sync_to(19).await;
node.wait_for_sync_to(9).await;

assert_eq!(
node.json_rpc().block_hash_and_number().await.unwrap(),
BlockHashAndNumber {
// https://sepolia.voyager.online/block/19
block_hash: Felt::from_hex_unchecked("0x4177d1ba942a4ab94f86a476c06f0f9e02363ad410cdf177c54064788c9bcb5"),
block_number: 19
// https://sepolia.voyager.online/block/9
block_hash: Felt::from_hex_unchecked("0x4174555d24718e8225a3d536ca96d2c4cc8a31bff6a6c758ab84a16a9e92d6c"),
block_number: 9
}
);
}
3 changes: 3 additions & 0 deletions tests/js_tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
lib
package-lock.json
node_modules
Loading
Loading