movehat 0.0.1-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 +236 -0
- package/bin/movehat.js +21 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +93 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/compile.d.ts +2 -0
- package/dist/commands/compile.d.ts.map +1 -0
- package/dist/commands/compile.js +71 -0
- package/dist/commands/compile.js.map +1 -0
- package/dist/commands/fork/create.d.ts +11 -0
- package/dist/commands/fork/create.d.ts.map +1 -0
- package/dist/commands/fork/create.js +56 -0
- package/dist/commands/fork/create.js.map +1 -0
- package/dist/commands/fork/fund.d.ts +12 -0
- package/dist/commands/fork/fund.d.ts.map +1 -0
- package/dist/commands/fork/fund.js +42 -0
- package/dist/commands/fork/fund.js.map +1 -0
- package/dist/commands/fork/list.d.ts +5 -0
- package/dist/commands/fork/list.d.ts.map +1 -0
- package/dist/commands/fork/list.js +61 -0
- package/dist/commands/fork/list.js.map +1 -0
- package/dist/commands/fork/serve.d.ts +10 -0
- package/dist/commands/fork/serve.d.ts.map +1 -0
- package/dist/commands/fork/serve.js +64 -0
- package/dist/commands/fork/serve.js.map +1 -0
- package/dist/commands/fork/view-resource.d.ts +11 -0
- package/dist/commands/fork/view-resource.d.ts.map +1 -0
- package/dist/commands/fork/view-resource.js +34 -0
- package/dist/commands/fork/view-resource.js.map +1 -0
- package/dist/commands/init.d.ts +2 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +90 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/run.d.ts +2 -0
- package/dist/commands/run.d.ts.map +1 -0
- package/dist/commands/run.js +51 -0
- package/dist/commands/run.js.map +1 -0
- package/dist/commands/test.d.ts +2 -0
- package/dist/commands/test.d.ts.map +1 -0
- package/dist/commands/test.js +35 -0
- package/dist/commands/test.js.map +1 -0
- package/dist/core/config.d.ts +15 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +121 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/contract.d.ts +20 -0
- package/dist/core/contract.d.ts.map +1 -0
- package/dist/core/contract.js +59 -0
- package/dist/core/contract.js.map +1 -0
- package/dist/core/deployments.d.ts +32 -0
- package/dist/core/deployments.d.ts.map +1 -0
- package/dist/core/deployments.js +122 -0
- package/dist/core/deployments.js.map +1 -0
- package/dist/core/shell.d.ts +25 -0
- package/dist/core/shell.d.ts.map +1 -0
- package/dist/core/shell.js +56 -0
- package/dist/core/shell.js.map +1 -0
- package/dist/errors.d.ts +12 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +24 -0
- package/dist/errors.js.map +1 -0
- package/dist/fork/api.d.ts +33 -0
- package/dist/fork/api.d.ts.map +1 -0
- package/dist/fork/api.js +98 -0
- package/dist/fork/api.js.map +1 -0
- package/dist/fork/manager.d.ts +52 -0
- package/dist/fork/manager.d.ts.map +1 -0
- package/dist/fork/manager.js +221 -0
- package/dist/fork/manager.js.map +1 -0
- package/dist/fork/server.d.ts +55 -0
- package/dist/fork/server.d.ts.map +1 -0
- package/dist/fork/server.js +274 -0
- package/dist/fork/server.js.map +1 -0
- package/dist/fork/storage.d.ts +63 -0
- package/dist/fork/storage.d.ts.map +1 -0
- package/dist/fork/storage.js +183 -0
- package/dist/fork/storage.js.map +1 -0
- package/dist/fork/test.d.ts +75 -0
- package/dist/fork/test.d.ts.map +1 -0
- package/dist/fork/test.js +157 -0
- package/dist/fork/test.js.map +1 -0
- package/dist/helpers/assertions.d.ts +7 -0
- package/dist/helpers/assertions.d.ts.map +1 -0
- package/dist/helpers/assertions.js +17 -0
- package/dist/helpers/assertions.js.map +1 -0
- package/dist/helpers/banner.d.ts +3 -0
- package/dist/helpers/banner.d.ts.map +1 -0
- package/dist/helpers/banner.js +38 -0
- package/dist/helpers/banner.js.map +1 -0
- package/dist/helpers/index.d.ts +11 -0
- package/dist/helpers/index.d.ts.map +1 -0
- package/dist/helpers/index.js +7 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/helpers/setup.d.ts +10 -0
- package/dist/helpers/setup.d.ts.map +1 -0
- package/dist/helpers/setup.js +28 -0
- package/dist/helpers/setup.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/runtime.d.ts +26 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +247 -0
- package/dist/runtime.js.map +1 -0
- package/dist/templates/.env.example +9 -0
- package/dist/templates/.mocharc.json +8 -0
- package/dist/templates/README.md +92 -0
- package/dist/templates/move/Counter.move +64 -0
- package/dist/templates/move/Move.toml +16 -0
- package/dist/templates/movehat.config.ts +37 -0
- package/dist/templates/package.json +24 -0
- package/dist/templates/scripts/deploy-counter.ts +48 -0
- package/dist/templates/tests/Counter.test.ts +75 -0
- package/dist/templates/tsconfig.json +15 -0
- package/dist/templates/types/movehat.d.ts +104 -0
- package/dist/types/config.d.ts +35 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +2 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/fork.d.ts +37 -0
- package/dist/types/fork.d.ts.map +1 -0
- package/dist/types/fork.js +5 -0
- package/dist/types/fork.js.map +1 -0
- package/dist/types/runtime.d.ts +28 -0
- package/dist/types/runtime.d.ts.map +1 -0
- package/dist/types/runtime.js +2 -0
- package/dist/types/runtime.js.map +1 -0
- package/package.json +66 -0
- package/src/cli.ts +106 -0
- package/src/commands/compile.ts +84 -0
- package/src/commands/fork/create.ts +70 -0
- package/src/commands/fork/fund.ts +57 -0
- package/src/commands/fork/list.ts +67 -0
- package/src/commands/fork/serve.ts +77 -0
- package/src/commands/fork/view-resource.ts +46 -0
- package/src/commands/init.ts +150 -0
- package/src/commands/run.ts +59 -0
- package/src/commands/test.ts +42 -0
- package/src/core/config.ts +151 -0
- package/src/core/contract.ts +97 -0
- package/src/core/deployments.ts +164 -0
- package/src/core/shell.ts +66 -0
- package/src/errors.ts +21 -0
- package/src/fork/api.ts +117 -0
- package/src/fork/manager.ts +264 -0
- package/src/fork/server.ts +311 -0
- package/src/fork/storage.ts +224 -0
- package/src/fork/test.ts +195 -0
- package/src/helpers/assertions.ts +29 -0
- package/src/helpers/banner.ts +47 -0
- package/src/helpers/index.ts +26 -0
- package/src/helpers/setup.ts +49 -0
- package/src/index.ts +17 -0
- package/src/runtime.ts +322 -0
- package/src/templates/.env.example +9 -0
- package/src/templates/.mocharc.json +8 -0
- package/src/templates/README.md +92 -0
- package/src/templates/move/Counter.move +64 -0
- package/src/templates/move/Move.toml +16 -0
- package/src/templates/movehat.config.ts +37 -0
- package/src/templates/package.json +24 -0
- package/src/templates/scripts/deploy-counter.ts +48 -0
- package/src/templates/tests/Counter.test.ts +75 -0
- package/src/templates/tsconfig.json +15 -0
- package/src/templates/types/movehat.d.ts +104 -0
- package/src/types/config.ts +36 -0
- package/src/types/fork.ts +41 -0
- package/src/types/runtime.ts +49 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# {{PROJECT_NAME}}
|
|
2
|
+
|
|
3
|
+
A Move smart contract project built with Movehat.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
- Node.js v18+
|
|
8
|
+
- [Movement CLI](https://docs.movementnetwork.xyz/devs/movementCLI)
|
|
9
|
+
|
|
10
|
+
## Getting Started
|
|
11
|
+
|
|
12
|
+
### 1. Install dependencies
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
### 2. Configure environment
|
|
19
|
+
|
|
20
|
+
Copy `.env.example` to `.env` and fill in your credentials:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
cp .env.example .env
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Edit `.env`:
|
|
27
|
+
```
|
|
28
|
+
MH_PRIVATE_KEY=your_private_key_here
|
|
29
|
+
MH_ACCOUNT=your_account_address_here
|
|
30
|
+
MH_NETWORK=testnet
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### 3. Update Move.toml
|
|
34
|
+
|
|
35
|
+
Edit `move/Move.toml` and set the `counter` address to your account address:
|
|
36
|
+
|
|
37
|
+
```toml
|
|
38
|
+
[addresses]
|
|
39
|
+
counter = "0xYOUR_ACCOUNT_ADDRESS"
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### 4. Compile contracts
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npm run compile
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### 5. Deploy
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npx tsx scripts/deploy-counter.ts
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Or use the Movement CLI directly:
|
|
55
|
+
```bash
|
|
56
|
+
movement move publish --package-dir ./move --profile default --assume-yes
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### 6. Run tests
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
npm test
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Project Structure
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
{{PROJECT_NAME}}/
|
|
69
|
+
├── move/ # Move smart contracts
|
|
70
|
+
│ ├── sources/
|
|
71
|
+
│ │ └── Counter.move
|
|
72
|
+
│ └── Move.toml
|
|
73
|
+
├── scripts/ # Deployment scripts
|
|
74
|
+
│ └── deploy-counter.ts
|
|
75
|
+
├── tests/ # Integration tests
|
|
76
|
+
│ └── Counter.test.ts
|
|
77
|
+
├── movehat.config.ts # Movehat configuration
|
|
78
|
+
└── .env # Environment variables (git-ignored)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Available Commands
|
|
82
|
+
|
|
83
|
+
- `npm run compile` - Compile Move contracts
|
|
84
|
+
- `npm test` - Run integration tests
|
|
85
|
+
- `npm run test:watch` - Run tests in watch mode
|
|
86
|
+
- `npx tsx scripts/deploy-counter.ts` - Deploy and initialize counter
|
|
87
|
+
|
|
88
|
+
## Learn More
|
|
89
|
+
|
|
90
|
+
- [Movement Documentation](https://docs.movementnetwork.xyz)
|
|
91
|
+
- [Aptos Move Book](https://move-language.github.io/move/)
|
|
92
|
+
- [Movehat GitHub](https://github.com/gilbertsahumada/movehat)
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
module counter::counter {
|
|
2
|
+
use std::signer;
|
|
3
|
+
use aptos_framework::event;
|
|
4
|
+
use aptos_framework::account;
|
|
5
|
+
|
|
6
|
+
struct Counter has key {
|
|
7
|
+
value: u64,
|
|
8
|
+
increment_events: event::EventHandle<IncrementEvent>,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
struct IncrementEvent has drop, store {
|
|
12
|
+
old_value: u64,
|
|
13
|
+
new_value: u64,
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/// Initialize counter for an account
|
|
17
|
+
public entry fun init(account: &signer) {
|
|
18
|
+
let account_addr = signer::address_of(account);
|
|
19
|
+
|
|
20
|
+
if (!exists<Counter>(account_addr)) {
|
|
21
|
+
move_to(account, Counter {
|
|
22
|
+
value: 0,
|
|
23
|
+
increment_events: account::new_event_handle<IncrementEvent>(account),
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/// Increment the counter
|
|
29
|
+
public entry fun increment(account: &signer) acquires Counter {
|
|
30
|
+
let account_addr = signer::address_of(account);
|
|
31
|
+
assert!(exists<Counter>(account_addr), 1);
|
|
32
|
+
|
|
33
|
+
let counter = borrow_global_mut<Counter>(account_addr);
|
|
34
|
+
let old_value = counter.value;
|
|
35
|
+
counter.value = old_value + 1;
|
|
36
|
+
|
|
37
|
+
event::emit_event(&mut counter.increment_events, IncrementEvent {
|
|
38
|
+
old_value,
|
|
39
|
+
new_value: counter.value,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/// Get counter value
|
|
44
|
+
#[view]
|
|
45
|
+
public fun get(addr: address): u64 acquires Counter {
|
|
46
|
+
assert!(exists<Counter>(addr), 1);
|
|
47
|
+
borrow_global<Counter>(addr).value
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
#[test(account = @0x1)]
|
|
51
|
+
public fun test_increment(account: &signer) acquires Counter {
|
|
52
|
+
let addr = signer::address_of(account);
|
|
53
|
+
aptos_framework::account::create_account_for_test(addr);
|
|
54
|
+
|
|
55
|
+
init(account);
|
|
56
|
+
assert!(get(addr) == 0, 0);
|
|
57
|
+
|
|
58
|
+
increment(account);
|
|
59
|
+
assert!(get(addr) == 1, 1);
|
|
60
|
+
|
|
61
|
+
increment(account);
|
|
62
|
+
assert!(get(addr) == 2, 2);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "{{PROJECT_NAME}}"
|
|
3
|
+
version = "1.0.0"
|
|
4
|
+
authors = []
|
|
5
|
+
|
|
6
|
+
[addresses]
|
|
7
|
+
counter = "_"
|
|
8
|
+
|
|
9
|
+
[dev-addresses]
|
|
10
|
+
|
|
11
|
+
[dependencies.AptosFramework]
|
|
12
|
+
git = "https://github.com/movementlabsxyz/aptos-core.git"
|
|
13
|
+
rev = "movement"
|
|
14
|
+
subdir = "aptos-move/framework/aptos-framework"
|
|
15
|
+
|
|
16
|
+
[dev-dependencies]
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import dotenv from "dotenv";
|
|
2
|
+
dotenv.config();
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
// Default network to use when no --network flag is provided
|
|
6
|
+
defaultNetwork: "testnet",
|
|
7
|
+
|
|
8
|
+
// Network configurations
|
|
9
|
+
networks: {
|
|
10
|
+
testnet: {
|
|
11
|
+
url: process.env.MOVEMENT_RPC_URL || "https://testnet.movementnetwork.xyz/v1",
|
|
12
|
+
chainId: "testnet",
|
|
13
|
+
},
|
|
14
|
+
mainnet: {
|
|
15
|
+
url: "https://mainnet.movementnetwork.xyz/v1",
|
|
16
|
+
chainId: "mainnet",
|
|
17
|
+
},
|
|
18
|
+
local: {
|
|
19
|
+
url: "http://localhost:8080/v1",
|
|
20
|
+
chainId: "local",
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
// Global accounts configuration (Hardhat-style)
|
|
25
|
+
// Uses PRIVATE_KEY from .env by default
|
|
26
|
+
// You can also specify accounts here directly:
|
|
27
|
+
// accounts: ["0x1234..."],
|
|
28
|
+
accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : [],
|
|
29
|
+
|
|
30
|
+
// Global settings
|
|
31
|
+
moveDir: "./move",
|
|
32
|
+
|
|
33
|
+
// Named addresses (can be overridden per-network in network config)
|
|
34
|
+
namedAddresses: {
|
|
35
|
+
// Example: counter: "0x1234...",
|
|
36
|
+
},
|
|
37
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{projectName}}",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "mocha",
|
|
7
|
+
"test:watch": "mocha --watch",
|
|
8
|
+
"deploy": "movehat run scripts/deploy-counter.ts"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"movehat": "^0.0.1-alpha.0",
|
|
12
|
+
"@aptos-labs/ts-sdk": "^5.1.5",
|
|
13
|
+
"dotenv": "^17.2.3"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@types/chai": "^5.2.3",
|
|
17
|
+
"@types/mocha": "^10.0.10",
|
|
18
|
+
"@types/node": "^24.10.1",
|
|
19
|
+
"chai": "^6.2.1",
|
|
20
|
+
"mocha": "^11.7.5",
|
|
21
|
+
"tsx": "^4.7.0",
|
|
22
|
+
"typescript": "^5.9.3"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { getMovehat, ModuleAlreadyDeployedError } from "movehat";
|
|
2
|
+
|
|
3
|
+
async function main() {
|
|
4
|
+
console.log("🚀 Deploying Counter contract...\n");
|
|
5
|
+
|
|
6
|
+
// Get the Movehat Runtime Environment
|
|
7
|
+
const mh = await getMovehat();
|
|
8
|
+
|
|
9
|
+
console.log(`✅ Runtime initialized`);
|
|
10
|
+
console.log(` Account: ${mh.account.accountAddress.toString()}`);
|
|
11
|
+
console.log(` Network: ${mh.network.name}`);
|
|
12
|
+
console.log(` RPC: ${mh.network.rpc}\n`);
|
|
13
|
+
|
|
14
|
+
// Deploy (publish) the module
|
|
15
|
+
// Automatically checks if already deployed and suggests --redeploy if needed
|
|
16
|
+
const deployment = await mh.deployContract("counter");
|
|
17
|
+
|
|
18
|
+
console.log(`\n✅ Module deployed at: ${deployment.address}::counter`);
|
|
19
|
+
if (deployment.txHash) {
|
|
20
|
+
console.log(` Transaction: ${deployment.txHash}`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Get contract instance
|
|
24
|
+
const counter = mh.getContract(deployment.address, "counter");
|
|
25
|
+
|
|
26
|
+
// Initialize the counter
|
|
27
|
+
console.log("\n📝 Initializing counter...");
|
|
28
|
+
const txResult = await counter.call(mh.account, "init", []);
|
|
29
|
+
|
|
30
|
+
console.log(`✅ Transaction hash: ${txResult.hash}`);
|
|
31
|
+
console.log(`✅ Counter initialized successfully!`);
|
|
32
|
+
|
|
33
|
+
// Verify
|
|
34
|
+
const value = await counter.view<number>("get", [
|
|
35
|
+
mh.account.accountAddress.toString()
|
|
36
|
+
]);
|
|
37
|
+
|
|
38
|
+
console.log(`\n📊 Initial counter value: ${value}`);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
main().catch((error) => {
|
|
42
|
+
// ModuleAlreadyDeployedError is already logged with full details by deployContract()
|
|
43
|
+
// For other errors, show the message
|
|
44
|
+
if (!(error instanceof ModuleAlreadyDeployedError)) {
|
|
45
|
+
console.error("❌ Deployment failed:", error?.message || error);
|
|
46
|
+
}
|
|
47
|
+
process.exit(1);
|
|
48
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { describe, it, before, after } from "mocha";
|
|
2
|
+
import { expect } from "chai";
|
|
3
|
+
import { getMovehat, type MovehatRuntime } from "movehat";
|
|
4
|
+
import type { MoveContract } from "movehat/helpers";
|
|
5
|
+
import { assertTransactionSuccess, snapshot } from "movehat/helpers";
|
|
6
|
+
|
|
7
|
+
describe("Counter Contract", () => {
|
|
8
|
+
let mh: MovehatRuntime;
|
|
9
|
+
let counter: MoveContract;
|
|
10
|
+
|
|
11
|
+
before(async function () {
|
|
12
|
+
this.timeout(30000);
|
|
13
|
+
|
|
14
|
+
// Initialize Movehat Runtime Environment
|
|
15
|
+
mh = await getMovehat();
|
|
16
|
+
|
|
17
|
+
console.log(`\n✅ Testing on ${mh.network.name}`);
|
|
18
|
+
console.log(` Account: ${mh.account.accountAddress.toString()}\n`);
|
|
19
|
+
|
|
20
|
+
// Get counter contract instance
|
|
21
|
+
counter = mh.getContract(
|
|
22
|
+
mh.account.accountAddress.toString(),
|
|
23
|
+
"counter"
|
|
24
|
+
);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe("Counter functionality", () => {
|
|
28
|
+
it("should initialize counter", async function () {
|
|
29
|
+
this.timeout(30000);
|
|
30
|
+
|
|
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}`);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("should increment counter", async function () {
|
|
43
|
+
this.timeout(30000);
|
|
44
|
+
|
|
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}`);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
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
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "NodeNext",
|
|
5
|
+
"moduleResolution": "NodeNext",
|
|
6
|
+
"lib": ["ES2022"],
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"strict": true,
|
|
10
|
+
"resolveJsonModule": true,
|
|
11
|
+
"outDir": "./dist"
|
|
12
|
+
},
|
|
13
|
+
"include": ["tests/**/*", "scripts/**/*", "movehat.config.ts"],
|
|
14
|
+
"exclude": ["node_modules", "dist", "move"]
|
|
15
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// Type declarations for movehat package
|
|
2
|
+
// This file is only for IDE support during template development
|
|
3
|
+
// It will NOT be copied to user projects
|
|
4
|
+
|
|
5
|
+
declare module 'movehat' {
|
|
6
|
+
import { Aptos, Account } from '@aptos-labs/ts-sdk';
|
|
7
|
+
|
|
8
|
+
export interface NetworkInfo {
|
|
9
|
+
name: string;
|
|
10
|
+
rpc: string;
|
|
11
|
+
chainId?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface MovehatConfig {
|
|
15
|
+
network: string;
|
|
16
|
+
rpc: string;
|
|
17
|
+
privateKey: string;
|
|
18
|
+
profile: string;
|
|
19
|
+
moveDir: string;
|
|
20
|
+
account: string;
|
|
21
|
+
namedAddresses?: Record<string, string>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface DeploymentInfo {
|
|
25
|
+
address: string;
|
|
26
|
+
moduleName: string;
|
|
27
|
+
network: string;
|
|
28
|
+
deployer: string;
|
|
29
|
+
timestamp: number;
|
|
30
|
+
txHash?: string;
|
|
31
|
+
blockNumber?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface MovehatRuntime {
|
|
35
|
+
config: MovehatConfig;
|
|
36
|
+
network: NetworkInfo;
|
|
37
|
+
aptos: Aptos;
|
|
38
|
+
account: Account;
|
|
39
|
+
accounts: Account[];
|
|
40
|
+
getContract: (address: string, moduleName: string) => any;
|
|
41
|
+
deployContract: (
|
|
42
|
+
moduleName: string,
|
|
43
|
+
options?: {
|
|
44
|
+
packageDir?: string;
|
|
45
|
+
}
|
|
46
|
+
) => Promise<DeploymentInfo>;
|
|
47
|
+
getDeployment: (moduleName: string) => DeploymentInfo | null;
|
|
48
|
+
getDeployments: () => Record<string, DeploymentInfo>;
|
|
49
|
+
getDeploymentAddress: (moduleName: string) => string | null;
|
|
50
|
+
createAccount: () => Account;
|
|
51
|
+
getAccount: (privateKey: string) => Account;
|
|
52
|
+
getAccountByIndex: (index: number) => Account;
|
|
53
|
+
switchNetwork: (networkName: string) => Promise<void>;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function getMovehat(): Promise<MovehatRuntime>;
|
|
57
|
+
export function initRuntime(configOverride?: Partial<MovehatConfig>): Promise<MovehatRuntime>;
|
|
58
|
+
export function getRuntime(): MovehatRuntime;
|
|
59
|
+
|
|
60
|
+
export const mh: {
|
|
61
|
+
readonly runtime: MovehatRuntime;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
declare module 'movehat/helpers' {
|
|
66
|
+
import { Account, Aptos } from '@aptos-labs/ts-sdk';
|
|
67
|
+
|
|
68
|
+
export interface TestEnvironment {
|
|
69
|
+
aptos: Aptos;
|
|
70
|
+
account: Account;
|
|
71
|
+
config: any;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export class MoveContract {
|
|
75
|
+
constructor(aptos: Aptos, address: string, moduleName: string);
|
|
76
|
+
call(sender: Account, functionName: string, args: any[]): Promise<any>;
|
|
77
|
+
view<T>(functionName: string, args: any[]): Promise<T>;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface TransactionResult {
|
|
81
|
+
hash: string;
|
|
82
|
+
success: boolean;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface DeploymentInfo {
|
|
86
|
+
address: string;
|
|
87
|
+
moduleName: string;
|
|
88
|
+
network: string;
|
|
89
|
+
deployer: string;
|
|
90
|
+
timestamp: number;
|
|
91
|
+
txHash?: string;
|
|
92
|
+
blockNumber?: string;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function setupTestEnvironment(): Promise<TestEnvironment>;
|
|
96
|
+
export function createTestAccount(): Account;
|
|
97
|
+
export function getContract(aptos: Aptos, address: string, moduleName: string): MoveContract;
|
|
98
|
+
export function assertTransactionSuccess(result: TransactionResult): void;
|
|
99
|
+
export function assertTransactionFailed(result: TransactionResult): void;
|
|
100
|
+
export function saveDeployment(deployment: DeploymentInfo): void;
|
|
101
|
+
export function loadDeployment(network: string, moduleName: string): DeploymentInfo | null;
|
|
102
|
+
export function getAllDeployments(network: string): Record<string, DeploymentInfo>;
|
|
103
|
+
export function getDeployedAddress(network: string, moduleName: string): string | null;
|
|
104
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for a single network
|
|
3
|
+
*/
|
|
4
|
+
export interface NetworkConfig {
|
|
5
|
+
url: string;
|
|
6
|
+
accounts?: string[]; // Optional: if not provided, uses global accounts
|
|
7
|
+
chainId?: string;
|
|
8
|
+
profile?: string;
|
|
9
|
+
namedAddresses?: Record<string, string>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* User configuration (what users write in movehat.config.ts)
|
|
14
|
+
*/
|
|
15
|
+
export interface MovehatUserConfig {
|
|
16
|
+
defaultNetwork?: string;
|
|
17
|
+
networks: Record<string, NetworkConfig>;
|
|
18
|
+
accounts?: string[]; // Global accounts (Hardhat-style)
|
|
19
|
+
moveDir?: string;
|
|
20
|
+
namedAddresses?: Record<string, string>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Resolved configuration (internal use - what runtime uses)
|
|
25
|
+
*/
|
|
26
|
+
export interface MovehatConfig {
|
|
27
|
+
network: string; // Active network name
|
|
28
|
+
rpc: string; // RPC endpoint
|
|
29
|
+
privateKey: string; // Primary account (accounts[0])
|
|
30
|
+
allAccounts: string[]; // All accounts for this network
|
|
31
|
+
profile: string; // Movement CLI profile
|
|
32
|
+
moveDir: string; // Move source directory
|
|
33
|
+
account: string; // Account address (derived from privateKey)
|
|
34
|
+
namedAddresses: Record<string, string>; // Merged named addresses
|
|
35
|
+
networkConfig: NetworkConfig; // Full network configuration
|
|
36
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fork system types for MoveHat
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface ForkMetadata {
|
|
6
|
+
network: string;
|
|
7
|
+
nodeUrl: string;
|
|
8
|
+
chainId: number;
|
|
9
|
+
ledgerVersion: string;
|
|
10
|
+
timestamp: string;
|
|
11
|
+
epoch: string;
|
|
12
|
+
blockHeight: string;
|
|
13
|
+
createdAt: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface AccountState {
|
|
17
|
+
sequenceNumber: string;
|
|
18
|
+
authenticationKey: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface LedgerInfo {
|
|
22
|
+
chain_id: number;
|
|
23
|
+
epoch: string;
|
|
24
|
+
ledger_version: string;
|
|
25
|
+
oldest_ledger_version: string;
|
|
26
|
+
ledger_timestamp: string;
|
|
27
|
+
node_role: string;
|
|
28
|
+
oldest_block_height: string;
|
|
29
|
+
block_height: string;
|
|
30
|
+
git_hash?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface AccountData {
|
|
34
|
+
sequence_number: string;
|
|
35
|
+
authentication_key: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface AccountResource {
|
|
39
|
+
type: string;
|
|
40
|
+
data: any;
|
|
41
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Aptos, Account } from "@aptos-labs/ts-sdk";
|
|
2
|
+
import { MovehatConfig } from "./config.js";
|
|
3
|
+
import { MoveContract } from "../core/contract.js";
|
|
4
|
+
import { DeploymentInfo } from "../core/deployments.js";
|
|
5
|
+
|
|
6
|
+
export interface NetworkInfo {
|
|
7
|
+
name: string;
|
|
8
|
+
rpc: string;
|
|
9
|
+
chainId?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface MovehatRuntime {
|
|
13
|
+
// Core configuration
|
|
14
|
+
config: MovehatConfig;
|
|
15
|
+
|
|
16
|
+
// Network information
|
|
17
|
+
network: NetworkInfo;
|
|
18
|
+
|
|
19
|
+
// Aptos client instance
|
|
20
|
+
aptos: Aptos;
|
|
21
|
+
|
|
22
|
+
// Default account from config (accounts[0])
|
|
23
|
+
account: Account;
|
|
24
|
+
|
|
25
|
+
// All accounts for this network
|
|
26
|
+
accounts: Account[];
|
|
27
|
+
|
|
28
|
+
// Helper functions
|
|
29
|
+
getContract: (address: string, moduleName: string) => MoveContract;
|
|
30
|
+
|
|
31
|
+
// Deployment functions
|
|
32
|
+
deployContract: (
|
|
33
|
+
moduleName: string,
|
|
34
|
+
options?: {
|
|
35
|
+
packageDir?: string;
|
|
36
|
+
}
|
|
37
|
+
) => Promise<DeploymentInfo>;
|
|
38
|
+
getDeployment: (moduleName: string) => DeploymentInfo | null;
|
|
39
|
+
getDeployments: () => Record<string, DeploymentInfo>;
|
|
40
|
+
getDeploymentAddress: (moduleName: string) => string | null;
|
|
41
|
+
|
|
42
|
+
// Account management
|
|
43
|
+
createAccount: () => Account;
|
|
44
|
+
getAccount: (privateKey: string) => Account;
|
|
45
|
+
getAccountByIndex: (index: number) => Account;
|
|
46
|
+
|
|
47
|
+
// Network switching
|
|
48
|
+
switchNetwork: (networkName: string) => Promise<void>;
|
|
49
|
+
}
|