Skip to content

Commit 3379863

Browse files
committed
Modify test to display output in the web page
1 parent 7d62eb3 commit 3379863

File tree

2 files changed

+51
-17
lines changed

2 files changed

+51
-17
lines changed

cardano-wasm/example/example.js

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,61 @@ async function get_protocol_params() {
99

1010
let protocolParams = await get_protocol_params();
1111

12+
const output = document.createElement("code");
13+
output.innerText = "";
14+
output.id = "test-output";
15+
document.body.appendChild(output);
16+
17+
function log(out) {
18+
console.log(out);
19+
if (typeof(out) == "object") {
20+
output.innerText += "> [object] {\n";
21+
for (let [key, val] of Object.entries(out)) {
22+
let text = val.toString();
23+
if (typeof(val) == "function") {
24+
text = text.split("{")[0];
25+
}
26+
output.innerText += "    " + key + ": " + text + "\n";
27+
}
28+
output.innerText += "  }\n";
29+
} else {
30+
output.innerText += "> " + JSON.stringify(out) + "\n";
31+
}
32+
}
33+
34+
function finish_test() {
35+
let finishTag = document.createElement("p");
36+
finishTag.innerText = "Finished test!";
37+
finishTag.id = "finish-tag";
38+
document.body.appendChild(finishTag);
39+
}
40+
1241
async function do_async_work() {
1342
let api = await promise;
14-
console.log("Api object:");
15-
console.log(api);
43+
log("Api object:");
44+
log(api);
1645

1746
let emptyTx = await api.newConwayTx();
18-
console.log("UnsignedTx object:");
19-
console.log(emptyTx);
47+
log("UnsignedTx object:");
48+
log(emptyTx);
2049

2150
let tx = await emptyTx.addTxInput("be6efd42a3d7b9a00d09d77a5d41e55ceaf0bd093a8aa8a893ce70d9caafd978", 0)
22-
.addSimpleTxOut("addr_test1vzpfxhjyjdlgk5c0xt8xw26avqxs52rtf69993j4tajehpcue4v2v", 10_000_000n)
51+
.addSimpleTxOut("addr_test1vzpfxhjyjdlgk5c0xt8xw26avqxs52rtf69993j4tajehpcue4v2v", 10_000_000n)
2352

2453
let feeEstimate = await tx.estimateMinFee(protocolParams, 1, 0, 0);
25-
console.log("Estimated fee:");
26-
console.log(feeEstimate);
54+
log("Estimated fee:");
55+
log(feeEstimate);
2756

2857
let signedTx = await tx.setFee(feeEstimate)
29-
.signWithPaymentKey("addr_sk1648253w4tf6fv5fk28dc7crsjsaw7d9ymhztd4favg3cwkhz7x8sl5u3ms");
30-
console.log("SignedTx object:");
31-
console.log(signedTx);
58+
.signWithPaymentKey("addr_sk1648253w4tf6fv5fk28dc7crsjsaw7d9ymhztd4favg3cwkhz7x8sl5u3ms");
59+
log("SignedTx object:");
60+
log(signedTx);
3261

3362
let txCbor = await signedTx.txToCbor();
34-
console.log("Tx CBOR:");
35-
console.log(txCbor);
63+
log("Tx CBOR:");
64+
log(txCbor);
65+
66+
finish_test();
3667
}
3768

3869
do_async_work().then(() => { });

cardano-wasm/example/index.html

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
<html>
2+
<head>
3+
<title>cardano-wasm test</title>
4+
</head>
5+
<body>
6+
<script type="module" src="./example.js"></script>
7+
<h1>Test output</h1>
8+
</body>
29

3-
<body>
4-
<script type="module" src="./example.js"></script>
5-
</body>
6-
7-
</html>
10+
</html>

0 commit comments

Comments
 (0)