Skip to content

Commit 1f1d0ac

Browse files
committed
update contract to not have this.state in the constructor
1 parent 86b7574 commit 1f1d0ac

File tree

6 files changed

+41
-18
lines changed

6 files changed

+41
-18
lines changed

templates/hyperweb/__tests__/simpleState.test.ts

+21-5
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import { assertIsDeliverTxSuccess } from '@cosmjs/stargate';
44

55
import path from "path";
66
import fs from 'fs';
7-
import { getSigningHyperwebClient, hyperweb } from 'hyperwebjs';
7+
import { getSigningHyperwebClient, hyperweb, google } from 'hyperwebjs';
88
import { useChain, generateMnemonic } from 'starshipjs';
99
import { sleep } from '../test-utils/sleep';
1010
import './setup.test';
1111

1212
describe('State Contract Tests', () => {
1313
let wallet, denom, address, queryClient, signingClient;
1414
let chainInfo, getCoin, getRpcEndpoint, creditFromFaucet;
15-
let contractCode, contractIndex;
15+
let contractCode, contractIndex, contractAddress;
1616
let fee;
1717

1818
beforeAll(async () => {
@@ -75,16 +75,32 @@ describe('State Contract Tests', () => {
7575
// Parse the response to get the contract index
7676
const response = hyperweb.hvm.MsgInstantiateResponse.fromProtoMsg(result.msgResponses[0]);
7777
contractIndex = response.index;
78+
contractAddress = response.address;
7879
expect(contractIndex).toBeGreaterThan(0);
79-
console.log(`Contract instantiated at index: ${contractIndex}`);
80+
console.log(`Contract instantiated at index: ${contractIndex} and address ${contractAddress}`);
81+
});
82+
83+
it('Perform init function', async () => {
84+
const msg = hyperweb.hvm.MessageComposer.fromPartial.eval({
85+
address: contractAddress,
86+
creator: address,
87+
callee: "init",
88+
args: []
89+
});
90+
91+
const result = await signingClient.signAndBroadcast(address, [msg], fee);
92+
assertIsDeliverTxSuccess(result);
93+
94+
const response = hyperweb.hvm.MsgEvalResponse.fromProtoMsg(result.msgResponses[0]);
95+
expect(response.result).toEqual("0");
8096
});
8197

8298
it('Perform increment evaluation', async () => {
8399
const msg = hyperweb.hvm.MessageComposer.fromPartial.eval({
100+
address: contractAddress,
84101
creator: address,
85102
callee: "inc",
86-
index: contractIndex,
87-
args: [10] as any[],
103+
args: ["10"]
88104
});
89105

90106
const result = await signingClient.signAndBroadcast(address, [msg], fee);

templates/hyperweb/dist/contracts/simpleState.js

+4-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/hyperweb/dist/contracts/simpleState.js.map

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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.0",
56+
"@hyperweb/build": "^1.0.1",
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.0",
71+
"hyperwebjs": "1.1.1",
7272
"jest": "^29.6.2",
7373
"prettier": "^3.0.2",
7474
"rimraf": "4.4.1",

templates/hyperweb/src/simple-state/index.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@ export default class Contract {
77

88
constructor() {
99
console.log("[Contract] constructor called");
10-
this.state.value = 0;
1110
}
1211

1312
reset() {
1413
console.log("[Contract] reset called");
1514
this.state.value = 0;
1615
}
1716

17+
init() {
18+
console.log("[Contract] init called");
19+
this.state.value = 0;
20+
}
21+
1822
inc(x: number) {
1923
console.log("[Contract] inc called");
2024
this.state.value += x;

templates/hyperweb/yarn.lock

+7-7
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,7 @@ __metadata:
12951295
languageName: node
12961296
linkType: hard
12971297

1298-
"@hyperweb/build@npm:^1.0.0":
1298+
"@hyperweb/build@npm:^1.0.1":
12991299
version: 1.0.1
13001300
resolution: "@hyperweb/build@npm:1.0.1"
13011301
dependencies:
@@ -7660,7 +7660,7 @@ __metadata:
76607660
resolution: "hyperweb@workspace:."
76617661
dependencies:
76627662
"@chain-registry/types": "npm:^0.50.18"
7663-
"@hyperweb/build": "npm:^1.0.0"
7663+
"@hyperweb/build": "npm:^1.0.1"
76647664
"@interchain-kit/core": "npm:0.0.1-beta.62"
76657665
"@interchain-kit/keplr-extension": "npm:0.0.1-beta.62"
76667666
"@interchain-kit/leap-extension": "npm:0.0.1-beta.62"
@@ -7681,7 +7681,7 @@ __metadata:
76817681
eslint-plugin-simple-import-sort: "npm:^10.0.0"
76827682
eslint-plugin-unused-imports: "npm:^3.0.0"
76837683
generate-lockfile: "npm:0.0.12"
7684-
hyperwebjs: "npm:1.0.0"
7684+
hyperwebjs: "npm:1.1.1"
76857685
interchain-kit: "npm:0.0.1-beta.62"
76867686
jest: "npm:^29.6.2"
76877687
next: "npm:^13"
@@ -7697,17 +7697,17 @@ __metadata:
76977697
languageName: unknown
76987698
linkType: soft
76997699

7700-
"hyperwebjs@npm:1.0.0":
7701-
version: 1.0.0
7702-
resolution: "hyperwebjs@npm:1.0.0"
7700+
"hyperwebjs@npm:1.1.1":
7701+
version: 1.1.1
7702+
resolution: "hyperwebjs@npm:1.1.1"
77037703
dependencies:
77047704
"@cosmjs/amino": "npm:0.32.3"
77057705
"@cosmjs/encoding": "npm:0.32.3"
77067706
"@cosmjs/math": "npm:0.32.3"
77077707
"@cosmjs/proto-signing": "npm:0.32.3"
77087708
"@cosmjs/stargate": "npm:0.32.3"
77097709
"@cosmology/lcd": "npm:^0.14.0"
7710-
checksum: 10c0/fe3c7f2347e1c8c70427f689ada560c21d62da6351b2d66986a0538e2ab32a922d55979428f20c4a340f59edb4207eea35d210f7256971c92fdb30638725a138
7710+
checksum: 10c0/5b82583914f8d053013490a160826d879642712e8960d1ea5ee1256c24e22b7c4bd013b4ad082b43c741d9fdd8d5c2c37514ae755be43b1808b801ec1baaa6f8
77117711
languageName: node
77127712
linkType: hard
77137713

0 commit comments

Comments
 (0)