diff --git a/.github/workflows/haskell-wasm.yml b/.github/workflows/haskell-wasm.yml index 3222d398cc..dd2b82ed10 100644 --- a/.github/workflows/haskell-wasm.yml +++ b/.github/workflows/haskell-wasm.yml @@ -142,6 +142,21 @@ jobs: run: | wasm32-wasi-cabal build cardano-wasm --no-semaphore -j1 --ghc-options="-j1" + - name: Prepare example + run: | + cp $(env -u CABAL_CONFIG wasm32-wasi-cabal list-bin exe:cardano-wasm | tail -n1) cardano-wasm/example/ + $(wasm32-wasi-ghc --print-libdir)/post-link.mjs -i "$(env -u CABAL_CONFIG wasm32-wasi-cabal list-bin exe:cardano-wasm | tail -n1)" -o cardano-wasm/example/cardano-wasm.js + cp cardano-wasm/lib-wrapper/* cardano-wasm/example/ + + - uses: rrbutani/use-nix-shell-action@v1 + with: + devShell: .#playwright + + - name: Run playwright test in example + run: | + httpserver -h localhost -a 127.0.0.1 -p 8080 cardano-wasm/example & + playwright test cardano-wasm/js-test/basic-test.spec.ts + # - name: Run tests # env: # TMPDIR: ${{ runner.temp }} diff --git a/cardano-wasm/example/example.js b/cardano-wasm/example/example.js index 4c58158830..743c4195a4 100644 --- a/cardano-wasm/example/example.js +++ b/cardano-wasm/example/example.js @@ -9,30 +9,61 @@ async function get_protocol_params() { let protocolParams = await get_protocol_params(); +const output = document.createElement("code"); +output.innerText = ""; +output.id = "test-output"; +document.body.appendChild(output); + +function log(out) { + console.log(out); + if (typeof(out) == "object") { + output.innerText += "> [object] {\n"; + for (let [key, val] of Object.entries(out)) { + let text = val.toString(); + if (typeof(val) == "function") { + text = text.split("{")[0]; + } + output.innerText += " " + key + ": " + text + "\n"; + } + output.innerText += " }\n"; + } else { + output.innerText += "> " + JSON.stringify(out) + "\n"; + } +} + +function finish_test() { + let finishTag = document.createElement("p"); + finishTag.innerText = "Finished test!"; + finishTag.id = "finish-tag"; + document.body.appendChild(finishTag); +} + async function do_async_work() { let api = await promise; - console.log("Api object:"); - console.log(api); + log("Api object:"); + log(api); let emptyTx = await api.newConwayTx(); - console.log("UnsignedTx object:"); - console.log(emptyTx); + log("UnsignedTx object:"); + log(emptyTx); let tx = await emptyTx.addTxInput("be6efd42a3d7b9a00d09d77a5d41e55ceaf0bd093a8aa8a893ce70d9caafd978", 0) - .addSimpleTxOut("addr_test1vzpfxhjyjdlgk5c0xt8xw26avqxs52rtf69993j4tajehpcue4v2v", 10_000_000n) + .addSimpleTxOut("addr_test1vzpfxhjyjdlgk5c0xt8xw26avqxs52rtf69993j4tajehpcue4v2v", 10_000_000n) let feeEstimate = await tx.estimateMinFee(protocolParams, 1, 0, 0); - console.log("Estimated fee:"); - console.log(feeEstimate); + log("Estimated fee:"); + log(feeEstimate); let signedTx = await tx.setFee(feeEstimate) - .signWithPaymentKey("addr_sk1648253w4tf6fv5fk28dc7crsjsaw7d9ymhztd4favg3cwkhz7x8sl5u3ms"); - console.log("SignedTx object:"); - console.log(signedTx); + .signWithPaymentKey("addr_sk1648253w4tf6fv5fk28dc7crsjsaw7d9ymhztd4favg3cwkhz7x8sl5u3ms"); + log("SignedTx object:"); + log(signedTx); let txCbor = await signedTx.txToCbor(); - console.log("Tx CBOR:"); - console.log(txCbor); + log("Tx CBOR:"); + log(txCbor); + + finish_test(); } do_async_work().then(() => { }); diff --git a/cardano-wasm/example/index.html b/cardano-wasm/example/index.html index 2efd25a184..3c6107bd9a 100644 --- a/cardano-wasm/example/index.html +++ b/cardano-wasm/example/index.html @@ -1,7 +1,10 @@ +
+