-
Notifications
You must be signed in to change notification settings - Fork 613
Expand file tree
/
Copy pathdeploy-and-interact.ts
More file actions
72 lines (62 loc) · 2.34 KB
/
Copy pathdeploy-and-interact.ts
File metadata and controls
72 lines (62 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// docs:start:script-setup
import { EmbeddedWallet } from "@aztec/wallets/embedded";
import { getInitialTestAccountsData } from "@aztec/accounts/testing";
// @ts-ignore — generated artifact, may not exist until compiled
import { PodRacingContract } from "../src/artifacts/PodRacing.js";
const nodeUrl = process.env.AZTEC_NODE_URL ?? "http://localhost:8080";
const wallet = await EmbeddedWallet.create(nodeUrl, { ephemeral: true });
const [alice, bob] = await getInitialTestAccountsData();
await wallet.createSchnorrAccount(alice.secret, alice.salt, alice.signingKey);
await wallet.createSchnorrAccount(bob.secret, bob.salt, bob.signingKey);
console.log(
"Accounts ready:",
alice.address.toString(),
bob.address.toString(),
);
// docs:end:script-setup
// docs:start:script-deploy
const { contract } = await PodRacingContract.deploy(wallet, alice.address).send(
{
from: alice.address,
},
);
console.log("Contract deployed at:", contract.address.toString());
// docs:end:script-deploy
// docs:start:script-create-join
const gameId = 1n;
await contract.methods.create_game(gameId).send({ from: alice.address });
console.log("Game created");
await contract.methods.join_game(gameId).send({ from: bob.address });
console.log("Bob joined the game");
// docs:end:script-create-join
// docs:start:script-play-rounds
// Round 1
await contract.methods
.play_round(gameId, 1, 3, 2, 1, 2, 1)
.send({ from: alice.address });
await contract.methods
.play_round(gameId, 1, 1, 1, 3, 2, 2)
.send({ from: bob.address });
// Round 2
await contract.methods
.play_round(gameId, 2, 2, 3, 1, 1, 2)
.send({ from: alice.address });
await contract.methods
.play_round(gameId, 2, 2, 2, 2, 2, 1)
.send({ from: bob.address });
// Round 3
await contract.methods
.play_round(gameId, 3, 1, 1, 2, 3, 2)
.send({ from: alice.address });
await contract.methods
.play_round(gameId, 3, 3, 1, 1, 1, 3)
.send({ from: bob.address });
console.log("All rounds played");
// docs:end:script-play-rounds
// docs:start:script-finish-finalize
await contract.methods.finish_game(gameId).send({ from: alice.address });
await contract.methods.finish_game(gameId).send({ from: bob.address });
console.log("Both players revealed scores");
await contract.methods.finalize_game(gameId).send({ from: alice.address });
console.log("Game finalized! Winner determined.");
// docs:end:script-finish-finalize