This repository was archived by the owner on Oct 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathsetup.jest.ts
95 lines (79 loc) · 2.42 KB
/
setup.jest.ts
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { JWKInterface } from 'arweave/node/lib/wallet';
import * as fs from 'fs';
import path from 'path';
import { IOState } from '../src/types';
import { WALLETS_TO_CREATE } from './utils/constants';
import { createLocalWallet, setupInitialContractState } from './utils/helper';
import { arlocal, arweave, warp } from './utils/services';
/* eslint-disable no-console */
module.exports = async () => {
// start arlocal
console.log('\n\nSetting up Warp, Arlocal and Arweave clients...');
await arlocal.start();
createDirectories();
// pull source code
const contractSrcJs = fs.readFileSync(
path.join(__dirname, '../dist/contract.js'),
'utf8',
);
// create owner wallet
const wallets: { wallet: JWKInterface; address: string }[] = [];
for (let i = 0; i < WALLETS_TO_CREATE; i++) {
wallets.push(await createLocalWallet(arweave));
}
// save wallets to disk
console.log('Saving wallets to disk!');
wallets.forEach((w, index) => {
fs.writeFileSync(
path.join(__dirname, `./wallets/${index}.json`),
JSON.stringify(w.wallet),
);
});
console.log('Successfully created wallets!');
// create initial contract
const initialContractState = await setupInitialContractState(
wallets[0].address,
wallets.map((w) => w.address),
);
console.log('Successfully created initial contract state!');
// deploy contract to arlocal
const { contractTxId, srcTxId } = await warp.deploy(
{
wallet: wallets[0].wallet,
initState: JSON.stringify(initialContractState),
src: contractSrcJs,
},
true,
); // disable bundling
console.log('Successfully deployed contract!', {
contractTxId,
srcTxId,
});
// transfer funds to the protocol balance
await warp
.contract<IOState>(contractTxId)
.connect(wallets[0].wallet)
.writeInteraction({
function: 'transfer',
target: contractTxId,
qty: 1, // just a hack for now - we'll need to give it a balance
});
// write contract to local
fs.writeFileSync(
path.join(__dirname, `./contract/arns_contract.json`),
JSON.stringify({
initialContractState,
id: contractTxId,
srcTxId: srcTxId,
}),
);
console.log('Successfully setup ArLocal and deployed contract.');
};
function createDirectories() {
['./wallets', './contract'].forEach((d) => {
const dir = path.join(__dirname, d);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
});
}