movehat 0.1.3 → 0.1.4
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.
- package/README.md +159 -80
- package/dist/commands/run.d.ts.map +1 -1
- package/dist/commands/run.js +40 -3
- package/dist/commands/run.js.map +1 -1
- package/dist/core/AccountManager.d.ts +186 -0
- package/dist/core/AccountManager.d.ts.map +1 -0
- package/dist/core/AccountManager.js +363 -0
- package/dist/core/AccountManager.js.map +1 -0
- package/dist/fork/manager.d.ts +33 -0
- package/dist/fork/manager.d.ts.map +1 -1
- package/dist/fork/manager.js +61 -0
- package/dist/fork/manager.js.map +1 -1
- package/dist/fork/storage.d.ts +10 -0
- package/dist/fork/storage.d.ts.map +1 -1
- package/dist/fork/storage.js +28 -1
- package/dist/fork/storage.js.map +1 -1
- package/dist/helpers/index.d.ts +8 -1
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/index.js +4 -0
- package/dist/helpers/index.js.map +1 -1
- package/dist/helpers/setup.d.ts.map +1 -1
- package/dist/helpers/setup.js +5 -4
- package/dist/helpers/setup.js.map +1 -1
- package/dist/helpers/setupLocalTesting.d.ts +60 -0
- package/dist/helpers/setupLocalTesting.d.ts.map +1 -0
- package/dist/helpers/setupLocalTesting.js +277 -0
- package/dist/helpers/setupLocalTesting.js.map +1 -0
- package/dist/helpers/testFixtures.d.ts +115 -0
- package/dist/helpers/testFixtures.d.ts.map +1 -0
- package/dist/helpers/testFixtures.js +163 -0
- package/dist/helpers/testFixtures.js.map +1 -0
- package/dist/node/LocalNodeManager.d.ts +68 -0
- package/dist/node/LocalNodeManager.d.ts.map +1 -0
- package/dist/node/LocalNodeManager.js +237 -0
- package/dist/node/LocalNodeManager.js.map +1 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +91 -46
- package/dist/runtime.js.map +1 -1
- package/dist/templates/README.md +17 -4
- package/dist/templates/move/sources/Counter.move +12 -4
- package/dist/templates/tests/Counter.test.ts +98 -57
- package/dist/types/config.d.ts +24 -0
- package/dist/types/config.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/commands/run.ts +43 -3
- package/src/core/AccountManager.ts +439 -0
- package/src/fork/manager.ts +74 -0
- package/src/fork/storage.ts +33 -1
- package/src/helpers/index.ts +18 -1
- package/src/helpers/setup.ts +4 -3
- package/src/helpers/setupLocalTesting.ts +335 -0
- package/src/helpers/testFixtures.ts +222 -0
- package/src/node/LocalNodeManager.ts +297 -0
- package/src/runtime.ts +108 -47
- package/src/templates/README.md +17 -4
- package/src/templates/move/sources/Counter.move +12 -4
- package/src/templates/tests/Counter.test.ts +98 -57
- package/src/types/config.ts +32 -0
|
@@ -1,72 +1,113 @@
|
|
|
1
1
|
// @ts-nocheck - This is a template file, dependencies are installed in user projects
|
|
2
|
-
import { describe, it, before } from "mocha";
|
|
2
|
+
import { describe, it, before, after } from "mocha";
|
|
3
3
|
import { expect } from "chai";
|
|
4
|
-
import {
|
|
4
|
+
import { setupTestFixture, teardownTestFixture, type TestFixture } from "movehat/helpers";
|
|
5
5
|
|
|
6
6
|
describe("Counter Contract", () => {
|
|
7
|
-
let
|
|
8
|
-
let contractAddress: string;
|
|
7
|
+
let fixture: TestFixture<'counter'>;
|
|
9
8
|
|
|
10
9
|
before(async function () {
|
|
11
|
-
this.timeout(
|
|
10
|
+
this.timeout(60000); // Allow time for local node startup + deployment
|
|
12
11
|
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
|
|
12
|
+
// Setup local testing environment with auto-deployment
|
|
13
|
+
// This will:
|
|
14
|
+
// 1. Start a local Movement blockchain node
|
|
15
|
+
// 2. Generate and fund test accounts from local faucet
|
|
16
|
+
// 3. Auto-deploy the counter module
|
|
17
|
+
// 4. Return everything ready to use
|
|
18
|
+
//
|
|
19
|
+
// By default uses 'local-node' mode (full blockchain)
|
|
20
|
+
// For faster tests on existing state, pass { mode: 'fork' }
|
|
21
|
+
//
|
|
22
|
+
// Note: Use 'as const' for type inference
|
|
23
|
+
fixture = await setupTestFixture(['counter'] as const, ['alice', 'bob']);
|
|
16
24
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
console.log(
|
|
20
|
-
console.log(`
|
|
25
|
+
console.log(`\n✅ Testing on local blockchain`);
|
|
26
|
+
console.log(` Deployer: ${fixture.accounts.deployer.accountAddress.toString()}`);
|
|
27
|
+
console.log(` Alice: ${fixture.accounts.alice.accountAddress.toString()}`);
|
|
28
|
+
console.log(` Bob: ${fixture.accounts.bob.accountAddress.toString()}\n`);
|
|
21
29
|
});
|
|
22
30
|
|
|
23
31
|
describe("Counter functionality", () => {
|
|
24
|
-
it("should initialize
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
console.log(`
|
|
32
|
+
it("should initialize with value 0", async () => {
|
|
33
|
+
const counter = fixture.contracts.counter; // Type-safe, no `!` needed
|
|
34
|
+
const deployer = fixture.accounts.deployer;
|
|
35
|
+
|
|
36
|
+
// Read counter value (returns string from view function)
|
|
37
|
+
const value = await counter.view<string>("get", [
|
|
38
|
+
deployer.accountAddress.toString()
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
console.log(` Counter value: ${value}`);
|
|
42
|
+
|
|
43
|
+
// Assert the counter is 0 (note: values from view are strings)
|
|
44
|
+
expect(parseInt(value)).to.equal(0);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("should increment counter", async () => {
|
|
48
|
+
const counter = fixture.contracts.counter;
|
|
49
|
+
const deployer = fixture.accounts.deployer;
|
|
50
|
+
|
|
51
|
+
// Increment the counter
|
|
52
|
+
const tx = await counter.call(deployer, "increment", []);
|
|
53
|
+
console.log(` Transaction: ${tx.hash}`);
|
|
54
|
+
|
|
55
|
+
// Read new value
|
|
56
|
+
const value = await counter.view<string>("get", [
|
|
57
|
+
deployer.accountAddress.toString()
|
|
58
|
+
]);
|
|
59
|
+
|
|
60
|
+
console.log(` New counter value: ${value}`);
|
|
61
|
+
|
|
62
|
+
// Should be 1 now
|
|
63
|
+
expect(parseInt(value)).to.equal(1);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("alice can also increment counter", async () => {
|
|
67
|
+
const counter = fixture.contracts.counter;
|
|
68
|
+
const alice = fixture.accounts.alice;
|
|
69
|
+
|
|
70
|
+
// Alice increments her own counter
|
|
71
|
+
const tx = await counter.call(alice, "increment", []);
|
|
72
|
+
console.log(` Alice's transaction: ${tx.hash}`);
|
|
73
|
+
|
|
74
|
+
// Read counter value for Alice (each user has their own counter)
|
|
75
|
+
const aliceValue = await counter.view<string>("get", [
|
|
76
|
+
alice.accountAddress.toString()
|
|
77
|
+
]);
|
|
78
|
+
|
|
79
|
+
console.log(` Alice's counter value: ${aliceValue}`);
|
|
80
|
+
expect(parseInt(aliceValue)).to.equal(1);
|
|
81
|
+
|
|
82
|
+
// Deployer's counter should still be 1 (unchanged)
|
|
83
|
+
const deployerValue = await counter.view<string>("get", [
|
|
84
|
+
fixture.accounts.deployer.accountAddress.toString()
|
|
85
|
+
]);
|
|
86
|
+
|
|
87
|
+
console.log(` Deployer's counter value: ${deployerValue}`);
|
|
88
|
+
expect(parseInt(deployerValue)).to.equal(1);
|
|
46
89
|
});
|
|
47
90
|
|
|
48
|
-
it("
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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}`);
|
|
91
|
+
it("bob can also increment the counter", async () => {
|
|
92
|
+
const counter = fixture.contracts.counter;
|
|
93
|
+
const bob = fixture.accounts.bob;
|
|
94
|
+
|
|
95
|
+
// Bob increments his own counter
|
|
96
|
+
const tx = await counter.call(bob, "increment", []);
|
|
97
|
+
console.log(` Bob's transaction: ${tx.hash}`);
|
|
98
|
+
|
|
99
|
+
// Read counter value for Bob (each user has their own counter)
|
|
100
|
+
const bobValue = await counter.view<string>("get", [
|
|
101
|
+
bob.accountAddress.toString()
|
|
102
|
+
]);
|
|
103
|
+
|
|
104
|
+
console.log(` Bob's counter value: ${bobValue}`);
|
|
105
|
+
expect(parseInt(bobValue)).to.equal(1);
|
|
70
106
|
});
|
|
71
107
|
});
|
|
72
|
-
|
|
108
|
+
|
|
109
|
+
after(async () => {
|
|
110
|
+
// Cleanup: Stop local node and clear account pool
|
|
111
|
+
await teardownTestFixture();
|
|
112
|
+
});
|
|
113
|
+
});
|
package/src/types/config.ts
CHANGED
|
@@ -33,4 +33,36 @@ export interface MovehatConfig {
|
|
|
33
33
|
account: string; // Account address (derived from privateKey)
|
|
34
34
|
namedAddresses: Record<string, string>; // Merged named addresses
|
|
35
35
|
networkConfig: NetworkConfig; // Full network configuration
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Testing mode for local environment
|
|
40
|
+
*/
|
|
41
|
+
export type LocalTestingMode = 'local-node' | 'fork';
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Options for setting up local testing environment
|
|
45
|
+
*/
|
|
46
|
+
export interface LocalTestOptions {
|
|
47
|
+
mode?: LocalTestingMode; // Testing mode: 'local-node' (full blockchain) or 'fork' (read-only snapshot) (default: 'local-node')
|
|
48
|
+
|
|
49
|
+
// Local Node options (when mode='local-node')
|
|
50
|
+
nodeTestDir?: string; // Directory for node data (default: .movehat/local-node)
|
|
51
|
+
nodeForceRestart?: boolean; // Clean node state and start fresh (default: true)
|
|
52
|
+
nodeFaucetPort?: number; // Faucet port for local node (default: 8081)
|
|
53
|
+
nodeApiPort?: number; // API/RPC port for local node (default: 8080)
|
|
54
|
+
nodeReadyPort?: number; // Ready server port (default: 8070)
|
|
55
|
+
nodeSilent?: boolean; // Suppress node output (default: false)
|
|
56
|
+
|
|
57
|
+
// Fork options (when mode='fork')
|
|
58
|
+
forkNetwork?: 'testnet' | string; // Network to fork from (default: 'testnet')
|
|
59
|
+
forkName?: string; // Name for the fork (default: 'test-local')
|
|
60
|
+
forkPort?: number; // Fork server port (default: 8080)
|
|
61
|
+
forkResetState?: boolean; // Clear fork state before tests (default: true)
|
|
62
|
+
|
|
63
|
+
// Common options (both modes)
|
|
64
|
+
autoFund?: boolean; // Auto-fund accounts (default: true)
|
|
65
|
+
defaultBalance?: number; // Default balance in octas (default: 100_000_000 = 100 APT)
|
|
66
|
+
autoDeploy?: readonly string[]; // Modules to auto-deploy (accepts readonly arrays)
|
|
67
|
+
accountLabels?: readonly string[]; // Labels for pre-generated accounts (default: ['deployer', 'alice', 'bob'])
|
|
36
68
|
}
|