This repository has been 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
/
evolve.test.ts
104 lines (93 loc) · 3.53 KB
/
evolve.test.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
96
97
98
99
100
101
102
103
104
import Arweave from 'arweave';
import {
Contract,
JWKInterface,
WarpFactory,
defaultCacheOptions,
} from 'warp-contracts';
import { DeployPlugin } from 'warp-contracts-plugin-deploy';
import { IOState } from '../src/types';
import {
getContractManifest,
getLocalArNSContractKey,
getLocalWallet,
} from './utils/helper';
import { arweave as arweaveLocal, warp as warpLocal } from './utils/services';
const testnetContractTxId =
process.env.ARNS_CONTRACT_TX_ID ??
'bLAgYxAdX2Ry-nt6aH2ixgvJXbpsEYm28NgJgyqfs-U';
const arweave = new Arweave({
host: 'ar-io.dev',
port: 443,
protocol: 'https',
});
const warpMainnet = WarpFactory.forMainnet(
{
...defaultCacheOptions,
},
true,
arweave,
).use(new DeployPlugin());
describe('evolving', () => {
let localContractOwnerJWK: JWKInterface;
let newForkedContract: Contract<IOState>;
let localSourceCodeId: string;
beforeAll(async () => {
localSourceCodeId = getLocalArNSContractKey('srcTxId');
localContractOwnerJWK = getLocalWallet(0);
// get the existing contract state
const { evaluationOptions = {} } = await getContractManifest({
arweave,
contractTxId: testnetContractTxId,
});
// fetches the currently deployed contract (on arweave.net) state against the most recent sort key
const testnetContract = await warpMainnet
.contract<IOState>(testnetContractTxId)
.setEvaluationOptions(evaluationOptions)
.syncState(`https://api.arns.app/v1/contract/${testnetContractTxId}`, {
validity: true,
});
const { cachedValue } = await testnetContract.readState();
const ownerAddress = await arweaveLocal.wallets.jwkToAddress(
localContractOwnerJWK,
);
// deploy a new contract locally using the deployed (arweave.net) contracts state to test that any code changes to not break the ability to evolve forward
const { contractTxId: newContractTxId } =
await warpLocal.deployFromSourceTx(
{
wallet: localContractOwnerJWK,
initState: JSON.stringify({
...(cachedValue.state as any),
owner: ownerAddress,
evolve: null,
}),
srcTxId: localSourceCodeId,
},
true,
);
newForkedContract = warpLocal
.contract<IOState>(newContractTxId)
.connect(localContractOwnerJWK);
});
// if this test fails, it means that we are going to lose our ability to evolve after the next contract update - VERY IMPORTANT to ensure this test is not modified or removed without thorough review
it('should be able evolve a newly deployed arns contract with a forked state using the new contract source', async () => {
const writeInteraction = await newForkedContract.evolve(localSourceCodeId);
expect(writeInteraction?.originalTxId).not.toBeUndefined();
const { cachedValue } = await newForkedContract.readState();
expect(Object.keys(cachedValue.errorMessages)).not.toContain(
writeInteraction?.originalTxId,
);
expect(cachedValue.state.evolve).toBe(localSourceCodeId);
});
// it('should be able to run evolve state on the new contract', async () => {
// const writeInteraction = await newForkedContract.writeInteraction({
// function: 'evolveState',
// });
// expect(writeInteraction?.originalTxId).not.toBeUndefined();
// const { cachedValue } = await newForkedContract.readState();
// expect(Object.keys(cachedValue.errorMessages)).not.toContain(
// writeInteraction?.originalTxId,
// );
// expect(cachedValue.state.evolve).toBe(localSourceCodeId);
// });
});