From 623c907071136696d3ede1ed0c37558d2081a20b Mon Sep 17 00:00:00 2001 From: Anmol Sharma Date: Tue, 19 Mar 2024 01:24:24 +0530 Subject: [PATCH] feat: use custome grader action Signed-off-by: Anmol Sharma --- .github/workflows/classroom.yml | 31 +++++++++++++++++++++++++++++++ grader/src/main.js | 7 +++++-- grader/src/validate-block.js | 4 ++++ 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/classroom.yml diff --git a/.github/workflows/classroom.yml b/.github/workflows/classroom.yml new file mode 100644 index 000000000..313b80551 --- /dev/null +++ b/.github/workflows/classroom.yml @@ -0,0 +1,31 @@ +name: Autograding Tests +'on': + - push + - workflow_dispatch + - repository_dispatch +permissions: + checks: write + actions: read + contents: read +jobs: + run-autograding-tests: + runs-on: ubuntu-latest + if: github.actor != 'github-classroom[bot]' + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: 'Validate block ' + id: validate-block + uses: SummerOfBitcoin/code-challenge-2024-grader@v1.1 + with: + test-name: 'Validate block ' + setup-command: chmod +x ./run.sh && ./run.sh + command: chmod +x ./test.sh && ./test.sh + timeout: 10 + max-score: 100 + - name: Autograding Reporter + uses: education/autograding-grading-reporter@v1 + env: + VALIDATE-BLOCK_RESULTS: "${{steps.validate-block.outputs.result}}" + with: + runners: validate-block diff --git a/grader/src/main.js b/grader/src/main.js index 4b4ab0963..29d8627e3 100644 --- a/grader/src/main.js +++ b/grader/src/main.js @@ -1,4 +1,4 @@ -import {readFileSync} from 'fs'; +import {readFileSync, writeFileSync} from 'fs'; import {validateHeader} from "./validate-header.js"; import {validateBlock} from "./validate-block.js"; @@ -18,7 +18,10 @@ export const run = async () => { await validateHeader(header, txids); // Validate the block - validateBlock(coinbase, txids); + const result = validateBlock(coinbase, txids); + + // Write the result to a file + writeFileSync('../result.json', JSON.stringify(result, null, 2)); } catch (error) { console.log(error.message); throw error; diff --git a/grader/src/validate-block.js b/grader/src/validate-block.js index 62ca7ceb0..fe5079d5a 100644 --- a/grader/src/validate-block.js +++ b/grader/src/validate-block.js @@ -74,4 +74,8 @@ export const validateBlock = (coinbase, txids) => { } console.log(`Congratulations! Block is valid with a total fee of ${totalFee} sats and a total weight of ${totalWeight}!`); + return { + fee: totalFee.toString(), + weight: totalWeight.toString(), + } } \ No newline at end of file