movehat 0.0.6-alpha.0 → 0.0.8-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,75 +1,72 @@
1
- import { describe, it, before, after } from "mocha";
1
+ // @ts-nocheck - This is a template file, dependencies are installed in user projects
2
+ import { describe, it, before } from "mocha";
2
3
  import { expect } from "chai";
3
4
  import { getMovehat, type MovehatRuntime } from "movehat";
4
- import type { MoveContract } from "movehat/helpers";
5
- import { assertTransactionSuccess, snapshot } from "movehat/helpers";
6
5
 
7
6
  describe("Counter Contract", () => {
8
7
  let mh: MovehatRuntime;
9
- let counter: MoveContract;
8
+ let contractAddress: string;
10
9
 
11
10
  before(async function () {
12
11
  this.timeout(30000);
13
12
 
14
13
  // Initialize Movehat Runtime Environment
14
+ // Uses testnet by default - no local setup required
15
15
  mh = await getMovehat();
16
16
 
17
- console.log(`\n✅ Testing on ${mh.network.name}`);
18
- console.log(` Account: ${mh.account.accountAddress.toString()}\n`);
17
+ contractAddress = mh.account.accountAddress.toString();
19
18
 
20
- // Get counter contract instance
21
- counter = mh.getContract(
22
- mh.account.accountAddress.toString(),
23
- "counter"
24
- );
19
+ console.log(`\nTesting on ${mh.network.name}`);
20
+ console.log(`Account: ${contractAddress}\n`);
25
21
  });
26
22
 
27
23
  describe("Counter functionality", () => {
28
- it("should initialize counter", async function () {
24
+ it("should initialize counter using simulation", async function () {
29
25
  this.timeout(30000);
30
26
 
31
- const txResult = await counter.call(mh.account, "init", []);
32
- assertTransactionSuccess(txResult);
33
-
34
- const value = await counter.view<number>("get", [
35
- mh.account.accountAddress.toString()
36
- ]);
37
-
38
- expect(value).to.equal(0);
39
- console.log(` ✓ Counter initialized with value: ${value}`);
27
+ // Build transaction
28
+ const transaction = await mh.aptos.transaction.build.simple({
29
+ sender: mh.account.accountAddress,
30
+ data: {
31
+ function: `${contractAddress}::counter::init`,
32
+ functionArguments: []
33
+ }
34
+ });
35
+
36
+ // Simulate transaction (no gas cost, instant)
37
+ const [simulation] = await mh.aptos.transaction.simulate.simple({
38
+ signerPublicKey: mh.account.publicKey,
39
+ transaction
40
+ });
41
+
42
+ // Verify simulation succeeded
43
+ expect(simulation.success).to.be.true;
44
+ console.log(`Counter init simulated successfully`);
45
+ console.log(`Gas used: ${simulation.gas_used}`);
40
46
  });
41
47
 
42
- it("should increment counter", async function () {
48
+ it("should increment counter using simulation", async function () {
43
49
  this.timeout(30000);
44
50
 
45
- const initialValue = await counter.view<number>("get", [
46
- mh.account.accountAddress.toString()
47
- ]);
48
-
49
- const txResult = await counter.call(mh.account, "increment", []);
50
- assertTransactionSuccess(txResult);
51
-
52
- const newValue = await counter.view<number>("get", [
53
- mh.account.accountAddress.toString()
54
- ]);
55
-
56
- expect(newValue).to.equal(initialValue + 1);
57
- console.log(` ✓ Counter incremented: ${initialValue} → ${newValue}`);
51
+ // Build increment transaction
52
+ const transaction = await mh.aptos.transaction.build.simple({
53
+ sender: mh.account.accountAddress,
54
+ data: {
55
+ function: `${contractAddress}::counter::increment`,
56
+ functionArguments: []
57
+ }
58
+ });
59
+
60
+ // Simulate transaction
61
+ const [simulation] = await mh.aptos.transaction.simulate.simple({
62
+ signerPublicKey: mh.account.publicKey,
63
+ transaction
64
+ });
65
+
66
+ // Verify simulation succeeded
67
+ expect(simulation.success).to.be.true;
68
+ console.log(`Counter increment simulated successfully`);
69
+ console.log(`Gas used: ${simulation.gas_used}`);
58
70
  });
59
71
  });
60
-
61
- // Optional: Create a snapshot after tests for debugging
62
- // Uncomment to enable
63
- /*
64
- after(async function () {
65
- this.timeout(30000);
66
-
67
- const snapshotPath = await snapshot({
68
- name: 'counter-test-final'
69
- });
70
-
71
- console.log(`\n📸 Snapshot created: ${snapshotPath}`);
72
- console.log(` Use 'aptos move sim view-resource --session ${snapshotPath}' to inspect state\n`);
73
- });
74
- */
75
72
  });