Skip to content

Commit 86b7574

Browse files
committed
update test cases
1 parent caa89ac commit 86b7574

File tree

4 files changed

+137
-164
lines changed

4 files changed

+137
-164
lines changed
+13-38
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,27 @@
1-
import path from "path";
1+
// @ts-nocheck
2+
import path from 'path';
23

3-
import { SigningClient } from "@interchainjs/cosmos/signing-client";
4-
import { DirectGenericOfflineSigner } from "@interchainjs/cosmos/types/wallet";
5-
import { Secp256k1HDWallet } from "@interchainjs/cosmos/wallets/secp256k1hd";
6-
import {
7-
ConfigContext,
8-
generateMnemonic,
9-
useChain,
10-
useRegistry,
11-
} from "starshipjs";
4+
import { StargateClient } from '@cosmjs/stargate';
5+
6+
import { ConfigContext, useChain, useRegistry } from 'starshipjs';
127

138
beforeAll(async () => {
14-
const configFile = path.join(__dirname, "..", "configs", "local.yaml");
9+
const configFile = path.join(__dirname, '..', 'configs', 'local.yaml');
1510
ConfigContext.setConfigFile(configFile);
1611
ConfigContext.setRegistry(await useRegistry(configFile));
1712
});
1813

19-
describe("Test clients", () => {
20-
let client: SigningClient;
14+
describe('Test clients', () => {
15+
let client;
2116

2217
beforeAll(async () => {
23-
const { getRpcEndpoint, chainInfo } = useChain("hyperweb");
24-
25-
const commonPrefix = chainInfo?.chain?.bech32_prefix;
26-
const cosmosHdPath = "m/44'/118'/0'/0/0";
27-
28-
const directWallet = Secp256k1HDWallet.fromMnemonic(generateMnemonic(), [
29-
{
30-
prefix: commonPrefix,
31-
hdPath: cosmosHdPath,
32-
},
33-
]);
34-
const directSigner = directWallet.toOfflineDirectSigner();
35-
36-
client = await SigningClient.connectWithSigner(
37-
await getRpcEndpoint(),
38-
new DirectGenericOfflineSigner(directSigner),
39-
{
40-
signerOptions: {
41-
prefix: commonPrefix,
42-
},
43-
}
44-
);
18+
const { getRpcEndpoint } = useChain('hyperweb');
19+
client = await StargateClient.connect(await getRpcEndpoint());
4520
});
4621

47-
it("check chain height", async () => {
48-
const { header } = await client.getBlock(1);
22+
it('check chain height', async () => {
23+
const height = await client.getHeight();
4924

50-
expect(header.height).toBeGreaterThan(0);
25+
expect(height).toBeGreaterThan(0);
5126
});
5227
});
+115-117
Original file line numberDiff line numberDiff line change
@@ -1,175 +1,173 @@
11
// @ts-nocheck
2-
import { Secp256k1HDWallet } from "@interchainjs/cosmos/wallets/secp256k1hd";
3-
import { assertIsDeliverTxSuccess } from "@interchainjs/cosmos/utils";
2+
import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing';
3+
import { assertIsDeliverTxSuccess } from '@cosmjs/stargate';
44

55
import path from "path";
6-
import fs from "fs";
7-
import { getSigningJsdClient, jsd } from "hyperwebjs";
8-
import { useChain, generateMnemonic } from "starshipjs";
9-
import { sleep } from "../test-utils/sleep";
10-
import "./setup.test";
11-
import { DirectGenericOfflineSigner } from "@interchainjs/cosmos/types/wallet";
12-
13-
describe("Simple state tests", () => {
6+
import fs from 'fs';
7+
import { getSigningHyperwebClient, hyperweb } from 'hyperwebjs';
8+
import { useChain, generateMnemonic } from 'starshipjs';
9+
import { sleep } from '../test-utils/sleep';
10+
import './setup.test';
11+
12+
describe('State Contract Tests', () => {
1413
let wallet, denom, address, queryClient, signingClient;
1514
let chainInfo, getCoin, getRpcEndpoint, creditFromFaucet;
1615
let contractCode, contractIndex;
17-
1816
let fee;
1917

2018
beforeAll(async () => {
21-
({ chainInfo, getCoin, getRpcEndpoint, creditFromFaucet } =
22-
useChain("hyperweb"));
19+
({
20+
chainInfo,
21+
getCoin,
22+
getRpcEndpoint,
23+
creditFromFaucet
24+
} = useChain('hyperweb'));
25+
2326
denom = (await getCoin()).base;
2427

2528
// Initialize wallet
26-
wallet = Secp256k1HDWallet.fromMnemonic(generateMnemonic(), [
27-
{
28-
prefix: chainInfo.chain.bech32_prefix,
29-
hdPath: "m/44'/118'/0'/0/0",
30-
},
31-
]);
29+
wallet = await DirectSecp256k1HdWallet.fromMnemonic(generateMnemonic(), {
30+
prefix: chainInfo.chain.bech32_prefix
31+
});
3232
address = (await wallet.getAccounts())[0].address;
33-
console.log(`contract creator address: ${address}`);
33+
console.log(`Contract creator address: ${address}`);
3434

3535
// Create custom cosmos interchain client
36-
queryClient = await jsd.ClientFactory.createRPCQueryClient({
37-
rpcEndpoint: await getRpcEndpoint(),
36+
queryClient = await hyperweb.ClientFactory.createRPCQueryClient({
37+
rpcEndpoint: await getRpcEndpoint()
3838
});
3939

40-
signingClient = await getSigningJsdClient({
40+
signingClient = await getSigningHyperwebClient({
4141
rpcEndpoint: await getRpcEndpoint(),
42-
signer: wallet,
42+
signer: wallet
4343
});
4444

45-
// set default fee
46-
fee = { amount: [{ denom, amount: "100000" }], gas: "550000" };
45+
// Set default transaction fee
46+
fee = { amount: [{ denom, amount: '100000' }], gas: '550000' };
4747

4848
await creditFromFaucet(address);
49-
await sleep(2000); // sleep for 1 sec to get tokens transferred from faucet successfully
49+
await sleep(2000); // Sleep for 2 sec to allow faucet tokens to arrive
5050
});
5151

52-
it("check balance", async () => {
52+
it('Check initial balance', async () => {
5353
const balance = await signingClient.getBalance(address, denom);
5454
expect(balance.amount).toEqual("10000000000");
5555
expect(balance.denom).toEqual(denom);
5656
});
5757

58-
it("instantiate contract", async () => {
58+
it('Instantiate state contract', async () => {
5959
// Read contract code from external file
6060
const contractPath = path.join(
6161
__dirname,
6262
"../dist/contracts/simpleState.js"
6363
);
6464
contractCode = fs.readFileSync(contractPath, "utf8");
6565

66-
const msg = jsd.jsd.MessageComposer.fromPartial.instantiate({
66+
const msg = hyperweb.hvm.MessageComposer.fromPartial.instantiate({
6767
creator: address,
6868
code: contractCode,
69+
source: "test_source",
6970
});
7071

7172
const result = await signingClient.signAndBroadcast(address, [msg], fee);
7273
assertIsDeliverTxSuccess(result);
7374

7475
// Parse the response to get the contract index
75-
const response = jsd.jsd.MsgInstantiateResponse.fromProtoMsg(
76-
result.msgResponses[0]
77-
);
76+
const response = hyperweb.hvm.MsgInstantiateResponse.fromProtoMsg(result.msgResponses[0]);
7877
contractIndex = response.index;
7978
expect(contractIndex).toBeGreaterThan(0);
80-
console.log(`contract index: ${contractIndex}`);
81-
});
82-
83-
it("query for contract based on index", async () => {
84-
const response = await queryClient.jsd.jsd.contracts({
85-
index: contractIndex,
86-
});
87-
expect(response.contracts.code).toEqual(contractCode);
88-
expect(response.contracts.index).toEqual(contractIndex);
89-
expect(response.contracts.creator).toEqual(address);
90-
});
91-
92-
it("query state before eval", async () => {
93-
const state = await queryClient.jsd.jsd.localState({
94-
index: contractIndex,
95-
key: "value",
96-
});
97-
expect(state).toEqual({ value: "" });
98-
});
99-
100-
it("perform inc eval", async () => {
101-
const msg = jsd.jsd.MessageComposer.fromPartial.eval({
102-
creator: address,
103-
index: contractIndex,
104-
fnName: "inc",
105-
arg: `{"x": 10}`,
106-
});
107-
108-
const result = await signingClient.signAndBroadcast(address, [msg], fee);
109-
assertIsDeliverTxSuccess(result);
110-
111-
const response = jsd.jsd.MsgEvalResponse.fromProtoMsg(
112-
result.msgResponses[0]
113-
);
114-
expect(response.result).toEqual("10");
79+
console.log(`Contract instantiated at index: ${contractIndex}`);
11580
});
11681

117-
it("eval read from eval", async () => {
118-
const msg = jsd.jsd.MessageComposer.fromPartial.eval({
82+
it('Perform increment evaluation', async () => {
83+
const msg = hyperweb.hvm.MessageComposer.fromPartial.eval({
11984
creator: address,
85+
callee: "inc",
12086
index: contractIndex,
121-
fnName: "read",
122-
arg: "",
87+
args: [10] as any[],
12388
});
12489

12590
const result = await signingClient.signAndBroadcast(address, [msg], fee);
12691
assertIsDeliverTxSuccess(result);
12792

128-
const response = jsd.jsd.MsgEvalResponse.fromProtoMsg(
129-
result.msgResponses[0]
130-
);
93+
const response = hyperweb.hvm.MsgEvalResponse.fromProtoMsg(result.msgResponses[0]);
13194
expect(response.result).toEqual("10");
13295
});
133-
134-
it("query state after eval", async () => {
135-
const state = await queryClient.jsd.jsd.localState({
136-
index: contractIndex,
137-
key: "value",
138-
});
139-
expect(state).toEqual({ value: "10" });
140-
});
141-
142-
it("perform dec eval", async () => {
143-
const msg = jsd.jsd.MessageComposer.fromPartial.eval({
144-
creator: address,
145-
index: contractIndex,
146-
fnName: "dec",
147-
arg: `{"x": 5}`,
148-
});
149-
150-
const result = await signingClient.signAndBroadcast(address, [msg], fee);
151-
assertIsDeliverTxSuccess(result);
152-
153-
const response = jsd.jsd.MsgEvalResponse.fromProtoMsg(
154-
result.msgResponses[0]
155-
);
156-
expect(response.result).toEqual("5");
157-
});
158-
159-
it("eval read from eval", async () => {
160-
const msg = jsd.jsd.MessageComposer.fromPartial.eval({
161-
creator: address,
162-
index: contractIndex,
163-
fnName: "read",
164-
arg: "",
165-
});
166-
167-
const result = await signingClient.signAndBroadcast(address, [msg], fee);
168-
assertIsDeliverTxSuccess(result);
169-
170-
const response = jsd.jsd.MsgEvalResponse.fromProtoMsg(
171-
result.msgResponses[0]
172-
);
173-
expect(response.result).toEqual("5");
174-
});
96+
//
97+
// it('Perform decrement evaluation', async () => {
98+
// const msg = hyperweb.hvm.MessageComposer.fromPartial.eval({
99+
// creator: address,
100+
// callee: "dec",
101+
// index: contractIndex,
102+
// args: []
103+
// });
104+
//
105+
// const result = await signingClient.signAndBroadcast(address, [msg], fee);
106+
// assertIsDeliverTxSuccess(result);
107+
//
108+
// const response = hyperweb.hvm.MsgEvalResponse.fromProtoMsg(result.msgResponses[0]);
109+
// expect(response.result).toEqual("0");
110+
// });
111+
//
112+
// it('Perform multiple increments and verify state', async () => {
113+
// for (let i = 0; i < 3; i++) {
114+
// const msg = hyperweb.hvm.MessageComposer.fromPartial.eval({
115+
// creator: address,
116+
// callee: "inc",
117+
// index: contractIndex,
118+
// args: []
119+
// });
120+
//
121+
// const result = await signingClient.signAndBroadcast(address, [msg], fee);
122+
// assertIsDeliverTxSuccess(result);
123+
// }
124+
//
125+
// const msgRead = hyperweb.hvm.MessageComposer.fromPartial.eval({
126+
// creator: address,
127+
// callee: "read",
128+
// index: contractIndex,
129+
// args: []
130+
// });
131+
//
132+
// const result = await signingClient.signAndBroadcast(address, [msgRead], fee);
133+
// assertIsDeliverTxSuccess(result);
134+
//
135+
// const response = hyperweb.hvm.MsgEvalResponse.fromProtoMsg(result.msgResponses[0]);
136+
// expect(response.result).toEqual("3");
137+
// });
138+
//
139+
// it('Perform reset and verify state', async () => {
140+
// const msg = hyperweb.hvm.MessageComposer.fromPartial.eval({
141+
// creator: address,
142+
// callee: "reset",
143+
// index: contractIndex,
144+
// args: []
145+
// });
146+
//
147+
// const result = await signingClient.signAndBroadcast(address, [msg], fee);
148+
// assertIsDeliverTxSuccess(result);
149+
//
150+
// const response = hyperweb.hvm.MsgEvalResponse.fromProtoMsg(result.msgResponses[0]);
151+
// expect(response.result).toEqual("0");
152+
// });
153+
//
154+
// it('Verify read function returns the correct state value', async () => {
155+
// const msg = hyperweb.hvm.MessageComposer.fromPartial.eval({
156+
// creator: address,
157+
// callee: "read",
158+
// index: contractIndex,
159+
// args: []
160+
// });
161+
//
162+
// const result = await signingClient.signAndBroadcast(address, [msg], fee);
163+
// assertIsDeliverTxSuccess(result);
164+
//
165+
// const response = hyperweb.hvm.MsgEvalResponse.fromProtoMsg(result.msgResponses[0]);
166+
// expect(response.result).toEqual("0");
167+
// });
168+
//
169+
// it('Retrieve contract source and validate', async () => {
170+
// const contractSource = await queryClient.hyperweb.hvm.getContractSource({ index: contractIndex });
171+
// expect(contractSource.source).toEqual("test_source");
172+
// });
175173
});

templates/hyperweb/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"react-icons": "4.6.0"
5454
},
5555
"devDependencies": {
56-
"@hyperweb/build": "^1.0.1",
56+
"@hyperweb/build": "^1.0.0",
5757
"@interchainjs/cosmos": "^1.9.12",
5858
"@starship-ci/cli": "^3.3.0",
5959
"@types/jest": "^29.5.11",
@@ -68,7 +68,7 @@
6868
"eslint-plugin-simple-import-sort": "^10.0.0",
6969
"eslint-plugin-unused-imports": "^3.0.0",
7070
"generate-lockfile": "0.0.12",
71-
"hyperwebjs": "1.0.1",
71+
"hyperwebjs": "1.0.0",
7272
"jest": "^29.6.2",
7373
"prettier": "^3.0.2",
7474
"rimraf": "4.4.1",

0 commit comments

Comments
 (0)