From f77e63abaa7ebedf1207ed65c9bb513994509e68 Mon Sep 17 00:00:00 2001 From: xlassix Date: Fri, 30 Aug 2024 07:56:51 +0100 Subject: [PATCH] chore: test batch 1 --- .github/workflows/node.js.yml | 24 ++++++++++++++++++++++++ orchestrator/src/indexer/rooch.ts | 2 +- rooch/sources/oracles.move | 16 ++++++++++------ 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 904d21f..2a71424 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -9,9 +9,14 @@ on: pull_request: branches: [main] + + jobs: build: runs-on: ubuntu-latest + strategy: + matrix: + node-version: [20.x] # env: # # ROOCH_ORACLE_ADDRESS= ${{ secrets.ROOCH_ORACLE_ADDRESS }} # # ROOCH_PRIVATE_KEY= ${{ secrets.ROOCH_PRIVATE_KEY }} @@ -32,3 +37,22 @@ jobs: - name: build run: npx yarn build + + # Set up Rust + - uses: actions/setup-rust@v1 + with: + toolchain: stable + + - name: Clone and setup Rooch + run: | + git clone https://github.com/rooch-network/rooch.git _rooch + cd _rooch + cargo build + cp target/debug/rooch ~/.cargo/bin/ + + + + + # Run tests + - run: rooch move test + - run: cargo test diff --git a/orchestrator/src/indexer/rooch.ts b/orchestrator/src/indexer/rooch.ts index 9ca76d1..15d6977 100644 --- a/orchestrator/src/indexer/rooch.ts +++ b/orchestrator/src/indexer/rooch.ts @@ -85,7 +85,7 @@ export default class RoochIndexer { const tx = new Transaction(); tx.callFunction({ target: `${this.oracleAddress}::oracles::fulfil_request`, - args: [Args.objectId(data.request_id), Args.string(result)], + args: [Args.objectId(data.request_id), Args.u8(status), Args.string(result)], }); const receipt = await client.signAndExecuteTransaction({ diff --git a/rooch/sources/oracles.move b/rooch/sources/oracles.move index c9d84cc..440d81d 100644 --- a/rooch/sources/oracles.move +++ b/rooch/sources/oracles.move @@ -127,7 +127,7 @@ module verity::oracles { params, pick, oracle, - status: 0, + response_status: 0, response: option::none(), }); let request_id = object::id(&request); @@ -153,7 +153,7 @@ module verity::oracles { public entry fun fulfil_request( sender: &signer, id: ObjectID, - status: u8, + response_status: u8, result: String // proof: String ) { @@ -170,7 +170,7 @@ module verity::oracles { // Fulfil the request request.response = option::some(result); - request.response_status = status; + request.response_status = response_status; // TODO: Move gas from module escrow to Oracle @@ -230,7 +230,7 @@ module verity::oracles { request.response } - public fun get_response_status(id: &ObjectID): Option { + public fun get_response_status(id: &ObjectID): u8 { let request = borrow_request(id); request.response_status } @@ -263,18 +263,19 @@ module verity::test_oracles { } /// Test function to consume the FulfilRequestObject - public fun fulfil_request(id: ObjectID) { + fun fulfil_request(id: ObjectID) { let result = string::utf8(b"Hello World"); // let proof = string::utf8(b""); let sig = signer::module_signer(); // oracles::fulfil_request(id, result, proof); - oracles::fulfil_request(&sig, id, result); + oracles::fulfil_request(&sig, id, 200, result); } #[test] public fun test_consume_fulfil_request() { + let id = create_oracle_request(); // Test the Object @@ -282,6 +283,7 @@ module verity::test_oracles { assert!(oracles::get_request_params_url(&id) == string::utf8(b"https://api.example.com/data"), 99952); assert!(oracles::get_request_params_method(&id) == string::utf8(b"GET"), 99953); assert!(oracles::get_request_params_body(&id) == string::utf8(b""), 99954); + assert!(oracles::get_response_status(&id) ==(0 as u8), 99955); // let recipient = object::owner(request_ref); // assert!(recipient == @0x46, 99955); @@ -289,5 +291,7 @@ module verity::test_oracles { fulfil_request(id); assert!(oracles::get_response(&id) == option::some(string::utf8(b"Hello World")), 99958); + assert!(oracles::get_response_status(&id) == (0 as u8), 99959); + } } \ No newline at end of file