Skip to content

Commit

Permalink
Add CI
Browse files Browse the repository at this point in the history
  • Loading branch information
jrchatruc committed Jun 11, 2024
1 parent 45831fb commit 1813a30
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 13 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: CI

on:
merge_group:
push:
branches: [ main ]
pull_request:
branches: [ '**' ]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
compile:
name: Compile
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Rustup toolchain install
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ env.RUST_VERSION }}

- name: Run cargo check
run: cargo check --workspace --all-features --all-targets

lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ env.RUST_VERSION }}
components: rustfmt, clippy

- name: Run cargo fmt
run: cargo fmt --all -- --check

# - name: Run clippy
# run: cargo clippy --workspace --all-features --benches --examples --tests -- -D warnings

test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ env.RUST_VERSION }}
components: clippy

- name: Install testing tools
uses: taiki-e/install-action@v2
with:
tool: cargo-nextest

- name: Run tests
run: cargo nextest run --workspace --all-features --no-capture
8 changes: 3 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@ pub fn run_program(bin_path: &str) -> U256 {

let program = std::fs::read(bin_path).unwrap();
let encoded = String::from_utf8(program.to_vec()).unwrap();
let bin = hex::decode(encoded[2..].to_owned()).unwrap();
let bin = hex::decode(&encoded[2..]).unwrap();

let mut program_code = vec![];
for raw_opcode_slice in bin.chunks(8) {
let mut raw_opcode_bytes: [u8; 8] = [0; 8];
for i in 0..8 {
raw_opcode_bytes[i] = raw_opcode_slice[i];
}
raw_opcode_bytes.copy_from_slice(&raw_opcode_slice[..8]);

let raw_opcode_u64 = u64::from_be_bytes(raw_opcode_bytes);
let opcode = Opcode::from_raw_opcode(raw_opcode_u64, &opcode_table);
Expand Down Expand Up @@ -76,5 +74,5 @@ pub fn run_program(bin_path: &str) -> U256 {
vm.current_frame.pc += 1;
}

vm.current_frame.storage.get(&U256::zero()).unwrap().clone()
*vm.current_frame.storage.get(&U256::zero()).unwrap()
}
10 changes: 4 additions & 6 deletions src/opcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl Opcode {
let imm0: u16 = ((raw_op & 0xffff00000000) >> 32) as u16;
let imm1: u16 = ((raw_op & 0xffff000000000000) >> 48) as u16;

let opcode = Opcode {
Self {
variant: opcode_zksync.opcode,
src0_operand_type: opcode_zksync.src0_operand_type,
dst0_operand_type: opcode_zksync.dst0_operand_type,
Expand All @@ -68,11 +68,9 @@ impl Opcode {
src1_index: second_four_bits(src0_and_1_index),
dst0_index: first_four_bits(dst0_and_1_index),
dst1_index: second_four_bits(dst0_and_1_index),
imm0: imm0,
imm1: imm1,
};

return opcode;
imm0,
imm1,
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl VMState {
return self.registers[(index - 1) as usize];
}

return U256::zero();
U256::zero()
}

pub fn set_register(&mut self, index: u8, value: U256) {
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ use u256::U256;
#[test]
fn test_add() {
let bin_path = "./program_artifacts/add.artifacts/add.yul.zbin";
let result = run_program(&bin_path);
let result = run_program(bin_path);
assert_eq!(result, U256::from_dec_str("3").unwrap());
}

0 comments on commit 1813a30

Please sign in to comment.