movehat 0.0.7-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.
- package/README.md +37 -20
- package/dist/commands/test.js +4 -4
- package/dist/commands/test.js.map +1 -1
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +50 -8
- package/dist/core/config.js.map +1 -1
- package/dist/templates/README.md +6 -0
- package/dist/templates/movehat.config.ts +10 -0
- package/dist/templates/package.json +1 -1
- package/dist/templates/tests/Counter.test.ts +47 -50
- package/package.json +1 -1
- package/src/commands/test.ts +4 -4
- package/src/core/config.ts +54 -10
- package/src/templates/README.md +6 -0
- package/src/templates/movehat.config.ts +10 -0
- package/src/templates/package.json +1 -1
- package/src/templates/tests/Counter.test.ts +47 -50
package/README.md
CHANGED
|
@@ -102,41 +102,58 @@ MH_NETWORK=testnet
|
|
|
102
102
|
|
|
103
103
|
## Writing Tests
|
|
104
104
|
|
|
105
|
+
Movehat uses **Transaction Simulation** for testing - no real blockchain or gas costs required:
|
|
106
|
+
|
|
105
107
|
```typescript
|
|
106
108
|
import { describe, it, before } from "mocha";
|
|
107
109
|
import { expect } from "chai";
|
|
108
|
-
import {
|
|
109
|
-
import type { TestEnvironment, MoveContract } from "movehat/helpers";
|
|
110
|
+
import { getMovehat, type MovehatRuntime } from "movehat";
|
|
110
111
|
|
|
111
112
|
describe("Counter Contract", () => {
|
|
112
|
-
let
|
|
113
|
-
let
|
|
113
|
+
let mh: MovehatRuntime;
|
|
114
|
+
let contractAddress: string;
|
|
114
115
|
|
|
115
116
|
before(async function () {
|
|
116
117
|
this.timeout(30000);
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
);
|
|
118
|
+
|
|
119
|
+
// Initialize Movehat Runtime Environment
|
|
120
|
+
// Uses Movement testnet by default with auto-generated test accounts
|
|
121
|
+
mh = await getMovehat();
|
|
122
|
+
contractAddress = mh.account.accountAddress.toString();
|
|
123
123
|
});
|
|
124
124
|
|
|
125
|
-
it("should
|
|
125
|
+
it("should initialize counter using simulation", async function () {
|
|
126
126
|
this.timeout(30000);
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
127
|
+
|
|
128
|
+
// Build transaction
|
|
129
|
+
const transaction = await mh.aptos.transaction.build.simple({
|
|
130
|
+
sender: mh.account.accountAddress,
|
|
131
|
+
data: {
|
|
132
|
+
function: `${contractAddress}::counter::init`,
|
|
133
|
+
functionArguments: []
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// Simulate transaction (no gas cost, instant)
|
|
138
|
+
const [simulation] = await mh.aptos.transaction.simulate.simple({
|
|
139
|
+
signerPublicKey: mh.account.publicKey,
|
|
140
|
+
transaction
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// Verify simulation succeeded
|
|
144
|
+
expect(simulation.success).to.be.true;
|
|
145
|
+
console.log(`Gas used: ${simulation.gas_used}`);
|
|
136
146
|
});
|
|
137
147
|
});
|
|
138
148
|
```
|
|
139
149
|
|
|
150
|
+
**Benefits of Transaction Simulation:**
|
|
151
|
+
- No blockchain or fork server required
|
|
152
|
+
- Instant test execution
|
|
153
|
+
- No gas costs
|
|
154
|
+
- Perfect for TDD and CI/CD
|
|
155
|
+
- Uses Movement testnet with auto-generated accounts by default
|
|
156
|
+
|
|
140
157
|
## Writing Deployment Scripts
|
|
141
158
|
|
|
142
159
|
```typescript
|
package/dist/commands/test.js
CHANGED
|
@@ -4,15 +4,15 @@ import { existsSync } from "fs";
|
|
|
4
4
|
export default async function testCommand() {
|
|
5
5
|
const testDir = join(process.cwd(), "tests");
|
|
6
6
|
if (!existsSync(testDir)) {
|
|
7
|
-
console.error("
|
|
7
|
+
console.error("No tests directory found.");
|
|
8
8
|
console.error(" Create a 'tests' directory with your TypeScript test files.");
|
|
9
9
|
process.exit(1);
|
|
10
10
|
}
|
|
11
|
-
console.log("
|
|
11
|
+
console.log("Running TypeScript tests with Mocha...\n");
|
|
12
12
|
// Find mocha from project's node_modules
|
|
13
13
|
const mochaPath = join(process.cwd(), "node_modules", ".bin", "mocha");
|
|
14
14
|
if (!existsSync(mochaPath)) {
|
|
15
|
-
console.error("
|
|
15
|
+
console.error("Mocha not found in project dependencies.");
|
|
16
16
|
console.error(" Install it with: npm install --save-dev mocha");
|
|
17
17
|
process.exit(1);
|
|
18
18
|
}
|
|
@@ -28,7 +28,7 @@ export default async function testCommand() {
|
|
|
28
28
|
process.exit(code || 0);
|
|
29
29
|
});
|
|
30
30
|
child.on("error", (error) => {
|
|
31
|
-
console.error(
|
|
31
|
+
console.error(`Failed to run tests: ${error.message}`);
|
|
32
32
|
process.exit(1);
|
|
33
33
|
});
|
|
34
34
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test.js","sourceRoot":"","sources":["../../src/commands/test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAEhC,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,WAAW;IACvC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,CAAC;IAE7C,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QACzB,OAAO,CAAC,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"test.js","sourceRoot":"","sources":["../../src/commands/test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CA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,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEtE;;;;;;GAMG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,iBAAiB,CAAC,CAyDjE;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,UAAU,EAAE,iBAAiB,EAC7B,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEtE;;;;;;GAMG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,iBAAiB,CAAC,CAyDjE;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,UAAU,EAAE,iBAAiB,EAC7B,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,aAAa,CAAC,CAoHxB"}
|
package/dist/core/config.js
CHANGED
|
@@ -62,16 +62,34 @@ export async function loadUserConfig() {
|
|
|
62
62
|
*/
|
|
63
63
|
export async function resolveNetworkConfig(userConfig, networkName) {
|
|
64
64
|
// Determine which network to use
|
|
65
|
+
// Default to "testnet" for testing with simulation
|
|
65
66
|
const selectedNetwork = networkName ||
|
|
66
67
|
process.env.MH_CLI_NETWORK ||
|
|
67
68
|
process.env.MH_DEFAULT_NETWORK ||
|
|
68
69
|
userConfig.defaultNetwork ||
|
|
69
70
|
"testnet";
|
|
70
71
|
// Check if network exists in config
|
|
71
|
-
|
|
72
|
+
let networkConfig = userConfig.networks[selectedNetwork];
|
|
73
|
+
// Special case: Auto-generate config for testnet (public test network)
|
|
74
|
+
// This provides a better dev experience - no local setup required
|
|
75
|
+
if (!networkConfig && selectedNetwork === "testnet") {
|
|
76
|
+
networkConfig = {
|
|
77
|
+
url: "https://testnet.movementnetwork.xyz/v1",
|
|
78
|
+
chainId: "testnet",
|
|
79
|
+
};
|
|
80
|
+
console.log(`testnet not found in config - using default Movement testnet configuration`);
|
|
81
|
+
}
|
|
82
|
+
// Special case: Auto-generate config for local fork server
|
|
83
|
+
if (!networkConfig && selectedNetwork === "local") {
|
|
84
|
+
networkConfig = {
|
|
85
|
+
url: "http://localhost:8080/v1",
|
|
86
|
+
chainId: "local",
|
|
87
|
+
};
|
|
88
|
+
console.log(`Local network not found in config - using default fork server configuration`);
|
|
89
|
+
}
|
|
72
90
|
if (!networkConfig) {
|
|
73
91
|
const availableNetworks = Object.keys(userConfig.networks).join(", ");
|
|
74
|
-
throw new Error(`Network '${selectedNetwork}' not found in configuration.\nAvailable networks: ${availableNetworks}`);
|
|
92
|
+
throw new Error(`Network '${selectedNetwork}' not found in configuration.\nAvailable networks: ${availableNetworks}, testnet (auto-generated), local (auto-generated)`);
|
|
75
93
|
}
|
|
76
94
|
// Get accounts using Hardhat-style resolution:
|
|
77
95
|
// 1. Network-specific accounts (if defined)
|
|
@@ -91,13 +109,37 @@ export async function resolveNetworkConfig(userConfig, networkName) {
|
|
|
91
109
|
if (accounts.length === 0 && process.env.PRIVATE_KEY) {
|
|
92
110
|
accounts = [process.env.PRIVATE_KEY];
|
|
93
111
|
}
|
|
94
|
-
// 4. Validate we have at least one account
|
|
112
|
+
// 4. Validate we have at least one account (unless using testnet/local)
|
|
95
113
|
if (accounts.length === 0 || !accounts[0]) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
114
|
+
// Special case: Auto-generate test accounts for testing networks
|
|
115
|
+
// testnet = public Movement test network (recommended)
|
|
116
|
+
// local = local fork server
|
|
117
|
+
if (selectedNetwork === "testnet" || selectedNetwork === "local") {
|
|
118
|
+
// Security: Using a deterministic test account (like Hardhat's default accounts)
|
|
119
|
+
// This is SAFE because:
|
|
120
|
+
// 1. Only used for testnet/local (never mainnet - that throws error below)
|
|
121
|
+
// 2. Perfect for transaction simulation (no real funds)
|
|
122
|
+
// 3. Deterministic = consistent test results
|
|
123
|
+
const testPrivateKey = "0x0000000000000000000000000000000000000000000000000000000000000001";
|
|
124
|
+
accounts = [testPrivateKey];
|
|
125
|
+
console.log(`\n[TESTNET] Using auto-generated test account (safe for testing only)`);
|
|
126
|
+
console.log(`[TESTNET] For mainnet, set PRIVATE_KEY in .env\n`);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
// For any other network (especially mainnet), REQUIRE explicit configuration
|
|
130
|
+
// This prevents accidentally using the test key on production networks
|
|
131
|
+
throw new Error(`Network '${selectedNetwork}' has no accounts configured.\n` +
|
|
132
|
+
`\n` +
|
|
133
|
+
`SECURITY: This network requires explicit account configuration.\n` +
|
|
134
|
+
`\n` +
|
|
135
|
+
`Options:\n` +
|
|
136
|
+
` 1. Set PRIVATE_KEY in your .env file (recommended for ${selectedNetwork})\n` +
|
|
137
|
+
` 2. Add 'accounts: ["0x..."]' globally in movehat.config.ts\n` +
|
|
138
|
+
` 3. Add 'accounts: ["0x..."]' to the '${selectedNetwork}' network config\n` +
|
|
139
|
+
`\n` +
|
|
140
|
+
`For testing without configuration, use:\n` +
|
|
141
|
+
` movehat <command> --network testnet (auto-generates safe test accounts)`);
|
|
142
|
+
}
|
|
101
143
|
}
|
|
102
144
|
// Merge named addresses (network-specific overrides global)
|
|
103
145
|
const mergedNamedAddresses = {
|
package/dist/core/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/core/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,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;YAC7E,uEAAuE;YACvE,MAAM,IAAI,KAAK,CACb,YAAY,eAAe,iCAAiC;gBAC5D,IAAI;gBACJ,mEAAmE;gBACnE,IAAI;gBACJ,YAAY;gBACZ,2DAA2D,eAAe,KAAK;gBAC/E,gEAAgE;gBAChE,0CAA0C,eAAe,oBAAoB;gBAC7E,IAAI;gBACJ,2CAA2C;gBAC3C,2EAA2E,CAC5E,CAAC;QACJ,CAAC;IACH,CAAC;IAED,4DAA4D;IAC5D,MAAM,oBAAoB,GAAG;QAC3B,GAAG,CAAC,UAAU,CAAC,cAAc,IAAI,EAAE,CAAC;QACpC,GAAG,CAAC,aAAa,CAAC,cAAc,IAAI,EAAE,CAAC;KACxC,CAAC;IAEF,wBAAwB;IACxB,MAAM,cAAc,GAAkB;QACpC,OAAO,EAAE,eAAe;QACxB,GAAG,EAAE,aAAa,CAAC,GAAG;QACtB,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;QACvB,WAAW,EAAE,QAAQ;QACrB,OAAO,EAAE,aAAa,CAAC,OAAO,IAAI,SAAS;QAC3C,OAAO,EAAE,UAAU,CAAC,OAAO,IAAI,QAAQ;QACvC,OAAO,EAAE,EAAE,EAAE,6CAA6C;QAC1D,cAAc,EAAE,oBAAoB;QACpC,aAAa,EAAE,aAAa;KAC7B,CAAC;IAEF,OAAO,cAAc,CAAC;AACxB,CAAC"}
|
package/dist/templates/README.md
CHANGED
|
@@ -52,6 +52,12 @@ npm run compile
|
|
|
52
52
|
npm test
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
+
**How it works:**
|
|
56
|
+
- Tests use **Transaction Simulation** - no real blockchain required
|
|
57
|
+
- Runs instantly without gas costs
|
|
58
|
+
- Uses Movement testnet by default with auto-generated test accounts
|
|
59
|
+
- Perfect for TDD and CI/CD workflows
|
|
60
|
+
|
|
55
61
|
### 5. Deploy (optional)
|
|
56
62
|
|
|
57
63
|
```bash
|
|
@@ -3,18 +3,28 @@ dotenv.config();
|
|
|
3
3
|
|
|
4
4
|
export default {
|
|
5
5
|
// Default network to use when no --network flag is provided
|
|
6
|
+
// "testnet" = Movement testnet (public, auto-generates test accounts)
|
|
7
|
+
// "mainnet" = Movement mainnet (requires PRIVATE_KEY in .env)
|
|
8
|
+
// "local" = Fork server running on localhost:8080
|
|
6
9
|
defaultNetwork: "testnet",
|
|
7
10
|
|
|
8
11
|
// Network configurations
|
|
9
12
|
networks: {
|
|
13
|
+
// Movement Testnet - Public test network (recommended for development)
|
|
14
|
+
// Auto-generates test accounts - no local setup required
|
|
15
|
+
// Perfect for running tests with transaction simulation
|
|
10
16
|
testnet: {
|
|
11
17
|
url: process.env.MOVEMENT_RPC_URL || "https://testnet.movementnetwork.xyz/v1",
|
|
12
18
|
chainId: "testnet",
|
|
13
19
|
},
|
|
20
|
+
// Movement Mainnet - Production network
|
|
21
|
+
// REQUIRES PRIVATE_KEY in .env - uses real MOVE tokens
|
|
14
22
|
mainnet: {
|
|
15
23
|
url: "https://mainnet.movementnetwork.xyz/v1",
|
|
16
24
|
chainId: "mainnet",
|
|
17
25
|
},
|
|
26
|
+
// Local fork server (requires: movehat fork serve)
|
|
27
|
+
// Useful for testing against a snapshot of real network state
|
|
18
28
|
local: {
|
|
19
29
|
url: "http://localhost:8080/v1",
|
|
20
30
|
chainId: "local",
|
|
@@ -1,75 +1,72 @@
|
|
|
1
|
-
|
|
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
|
|
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
|
-
|
|
18
|
-
console.log(` Account: ${mh.account.accountAddress.toString()}\n`);
|
|
17
|
+
contractAddress = mh.account.accountAddress.toString();
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
});
|
package/package.json
CHANGED
package/src/commands/test.ts
CHANGED
|
@@ -6,18 +6,18 @@ export default async function testCommand() {
|
|
|
6
6
|
const testDir = join(process.cwd(), "tests");
|
|
7
7
|
|
|
8
8
|
if (!existsSync(testDir)) {
|
|
9
|
-
console.error("
|
|
9
|
+
console.error("No tests directory found.");
|
|
10
10
|
console.error(" Create a 'tests' directory with your TypeScript test files.");
|
|
11
11
|
process.exit(1);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
console.log("
|
|
14
|
+
console.log("Running TypeScript tests with Mocha...\n");
|
|
15
15
|
|
|
16
16
|
// Find mocha from project's node_modules
|
|
17
17
|
const mochaPath = join(process.cwd(), "node_modules", ".bin", "mocha");
|
|
18
18
|
|
|
19
19
|
if (!existsSync(mochaPath)) {
|
|
20
|
-
console.error("
|
|
20
|
+
console.error("Mocha not found in project dependencies.");
|
|
21
21
|
console.error(" Install it with: npm install --save-dev mocha");
|
|
22
22
|
process.exit(1);
|
|
23
23
|
}
|
|
@@ -36,7 +36,7 @@ export default async function testCommand() {
|
|
|
36
36
|
});
|
|
37
37
|
|
|
38
38
|
child.on("error", (error) => {
|
|
39
|
-
console.error(
|
|
39
|
+
console.error(`Failed to run tests: ${error.message}`);
|
|
40
40
|
process.exit(1);
|
|
41
41
|
});
|
|
42
42
|
}
|
package/src/core/config.ts
CHANGED
|
@@ -78,6 +78,7 @@ export async function resolveNetworkConfig(
|
|
|
78
78
|
networkName?: string
|
|
79
79
|
): Promise<MovehatConfig> {
|
|
80
80
|
// Determine which network to use
|
|
81
|
+
// Default to "testnet" for testing with simulation
|
|
81
82
|
const selectedNetwork =
|
|
82
83
|
networkName ||
|
|
83
84
|
process.env.MH_CLI_NETWORK ||
|
|
@@ -86,11 +87,31 @@ export async function resolveNetworkConfig(
|
|
|
86
87
|
"testnet";
|
|
87
88
|
|
|
88
89
|
// Check if network exists in config
|
|
89
|
-
|
|
90
|
+
let networkConfig = userConfig.networks[selectedNetwork];
|
|
91
|
+
|
|
92
|
+
// Special case: Auto-generate config for testnet (public test network)
|
|
93
|
+
// This provides a better dev experience - no local setup required
|
|
94
|
+
if (!networkConfig && selectedNetwork === "testnet") {
|
|
95
|
+
networkConfig = {
|
|
96
|
+
url: "https://testnet.movementnetwork.xyz/v1",
|
|
97
|
+
chainId: "testnet",
|
|
98
|
+
};
|
|
99
|
+
console.log(`testnet not found in config - using default Movement testnet configuration`);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Special case: Auto-generate config for local fork server
|
|
103
|
+
if (!networkConfig && selectedNetwork === "local") {
|
|
104
|
+
networkConfig = {
|
|
105
|
+
url: "http://localhost:8080/v1",
|
|
106
|
+
chainId: "local",
|
|
107
|
+
};
|
|
108
|
+
console.log(`Local network not found in config - using default fork server configuration`);
|
|
109
|
+
}
|
|
110
|
+
|
|
90
111
|
if (!networkConfig) {
|
|
91
112
|
const availableNetworks = Object.keys(userConfig.networks).join(", ");
|
|
92
113
|
throw new Error(
|
|
93
|
-
`Network '${selectedNetwork}' not found in configuration.\nAvailable networks: ${availableNetworks}`
|
|
114
|
+
`Network '${selectedNetwork}' not found in configuration.\nAvailable networks: ${availableNetworks}, testnet (auto-generated), local (auto-generated)`
|
|
94
115
|
);
|
|
95
116
|
}
|
|
96
117
|
|
|
@@ -117,15 +138,38 @@ export async function resolveNetworkConfig(
|
|
|
117
138
|
accounts = [process.env.PRIVATE_KEY];
|
|
118
139
|
}
|
|
119
140
|
|
|
120
|
-
// 4. Validate we have at least one account
|
|
141
|
+
// 4. Validate we have at least one account (unless using testnet/local)
|
|
121
142
|
if (accounts.length === 0 || !accounts[0]) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
143
|
+
// Special case: Auto-generate test accounts for testing networks
|
|
144
|
+
// testnet = public Movement test network (recommended)
|
|
145
|
+
// local = local fork server
|
|
146
|
+
if (selectedNetwork === "testnet" || selectedNetwork === "local") {
|
|
147
|
+
// Security: Using a deterministic test account (like Hardhat's default accounts)
|
|
148
|
+
// This is SAFE because:
|
|
149
|
+
// 1. Only used for testnet/local (never mainnet - that throws error below)
|
|
150
|
+
// 2. Perfect for transaction simulation (no real funds)
|
|
151
|
+
// 3. Deterministic = consistent test results
|
|
152
|
+
const testPrivateKey = "0x0000000000000000000000000000000000000000000000000000000000000001";
|
|
153
|
+
accounts = [testPrivateKey];
|
|
154
|
+
console.log(`\n[TESTNET] Using auto-generated test account (safe for testing only)`);
|
|
155
|
+
console.log(`[TESTNET] For mainnet, set PRIVATE_KEY in .env\n`);
|
|
156
|
+
} else {
|
|
157
|
+
// For any other network (especially mainnet), REQUIRE explicit configuration
|
|
158
|
+
// This prevents accidentally using the test key on production networks
|
|
159
|
+
throw new Error(
|
|
160
|
+
`Network '${selectedNetwork}' has no accounts configured.\n` +
|
|
161
|
+
`\n` +
|
|
162
|
+
`SECURITY: This network requires explicit account configuration.\n` +
|
|
163
|
+
`\n` +
|
|
164
|
+
`Options:\n` +
|
|
165
|
+
` 1. Set PRIVATE_KEY in your .env file (recommended for ${selectedNetwork})\n` +
|
|
166
|
+
` 2. Add 'accounts: ["0x..."]' globally in movehat.config.ts\n` +
|
|
167
|
+
` 3. Add 'accounts: ["0x..."]' to the '${selectedNetwork}' network config\n` +
|
|
168
|
+
`\n` +
|
|
169
|
+
`For testing without configuration, use:\n` +
|
|
170
|
+
` movehat <command> --network testnet (auto-generates safe test accounts)`
|
|
171
|
+
);
|
|
172
|
+
}
|
|
129
173
|
}
|
|
130
174
|
|
|
131
175
|
// Merge named addresses (network-specific overrides global)
|
package/src/templates/README.md
CHANGED
|
@@ -52,6 +52,12 @@ npm run compile
|
|
|
52
52
|
npm test
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
+
**How it works:**
|
|
56
|
+
- Tests use **Transaction Simulation** - no real blockchain required
|
|
57
|
+
- Runs instantly without gas costs
|
|
58
|
+
- Uses Movement testnet by default with auto-generated test accounts
|
|
59
|
+
- Perfect for TDD and CI/CD workflows
|
|
60
|
+
|
|
55
61
|
### 5. Deploy (optional)
|
|
56
62
|
|
|
57
63
|
```bash
|
|
@@ -3,18 +3,28 @@ dotenv.config();
|
|
|
3
3
|
|
|
4
4
|
export default {
|
|
5
5
|
// Default network to use when no --network flag is provided
|
|
6
|
+
// "testnet" = Movement testnet (public, auto-generates test accounts)
|
|
7
|
+
// "mainnet" = Movement mainnet (requires PRIVATE_KEY in .env)
|
|
8
|
+
// "local" = Fork server running on localhost:8080
|
|
6
9
|
defaultNetwork: "testnet",
|
|
7
10
|
|
|
8
11
|
// Network configurations
|
|
9
12
|
networks: {
|
|
13
|
+
// Movement Testnet - Public test network (recommended for development)
|
|
14
|
+
// Auto-generates test accounts - no local setup required
|
|
15
|
+
// Perfect for running tests with transaction simulation
|
|
10
16
|
testnet: {
|
|
11
17
|
url: process.env.MOVEMENT_RPC_URL || "https://testnet.movementnetwork.xyz/v1",
|
|
12
18
|
chainId: "testnet",
|
|
13
19
|
},
|
|
20
|
+
// Movement Mainnet - Production network
|
|
21
|
+
// REQUIRES PRIVATE_KEY in .env - uses real MOVE tokens
|
|
14
22
|
mainnet: {
|
|
15
23
|
url: "https://mainnet.movementnetwork.xyz/v1",
|
|
16
24
|
chainId: "mainnet",
|
|
17
25
|
},
|
|
26
|
+
// Local fork server (requires: movehat fork serve)
|
|
27
|
+
// Useful for testing against a snapshot of real network state
|
|
18
28
|
local: {
|
|
19
29
|
url: "http://localhost:8080/v1",
|
|
20
30
|
chainId: "local",
|
|
@@ -1,75 +1,72 @@
|
|
|
1
|
-
|
|
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
|
|
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
|
-
|
|
18
|
-
console.log(` Account: ${mh.account.accountAddress.toString()}\n`);
|
|
17
|
+
contractAddress = mh.account.accountAddress.toString();
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
});
|