Skip to content

Commit 9aa2a08

Browse files
committed
inital boilerplate based on cca
0 parents  commit 9aa2a08

17 files changed

+6180
-0
lines changed

.eslintrc.json

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es2021": true,
5+
"node": true,
6+
"jest": true
7+
},
8+
"extends": [
9+
"eslint:recommended",
10+
"plugin:@typescript-eslint/recommended",
11+
"prettier"
12+
],
13+
"overrides": [],
14+
"parser": "@typescript-eslint/parser",
15+
"parserOptions": {
16+
"ecmaVersion": "latest",
17+
"sourceType": "module"
18+
},
19+
"plugins": ["@typescript-eslint", "simple-import-sort", "unused-imports"],
20+
"rules": {
21+
"simple-import-sort/imports": 1,
22+
"simple-import-sort/exports": 1,
23+
"unused-imports/no-unused-imports": 1,
24+
"@typescript-eslint/no-unused-vars": [
25+
1,
26+
{
27+
"argsIgnorePattern": "React|res|next|^_"
28+
}
29+
],
30+
"@typescript-eslint/no-explicit-any": 0,
31+
"@typescript-eslint/no-var-requires": 0,
32+
"no-console": 0,
33+
"@typescript-eslint/ban-ts-comment": 0,
34+
"prefer-const": 0,
35+
"no-case-declarations": 0,
36+
"no-implicit-globals": 0,
37+
"@typescript-eslint/no-unsafe-declaration-merging": 0
38+
}
39+
}

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
**/node_modules/
2+
**/.DS_Store
3+
**/dist
4+
**/yarn-error.log
5+
lerna-debug.log

.prettierrc.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"trailingComma": "es5",
3+
"tabWidth": 2,
4+
"semi": true,
5+
"singleQuote": false
6+
}

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2024 Anmol Yadav <[email protected]>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# hyperweb

__tests__/first.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { join } from 'path';
2+
3+
it('works', () => {
4+
console.log('hello test world!' + join('a/d/d/', 'b/c'));
5+
})

__tests__/setup.test.ts

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// @ts-nocheck
2+
import path from 'path';
3+
4+
import { StargateClient } from '@cosmjs/stargate';
5+
6+
import { ConfigContext, useChain, useRegistry } from 'starshipjs';
7+
8+
beforeAll(async () => {
9+
const configFile = path.join(__dirname, '..', 'configs', 'local.yaml');
10+
ConfigContext.setConfigFile(configFile);
11+
ConfigContext.setRegistry(await useRegistry(configFile));
12+
});
13+
14+
describe('Test clients', () => {
15+
let client;
16+
17+
beforeAll(async () => {
18+
const { getRpcEndpoint } = useChain('jsd');
19+
client = await StargateClient.connect(await getRpcEndpoint());
20+
});
21+
22+
it('check chain height', async () => {
23+
const height = await client.getHeight();
24+
25+
expect(height).toBeGreaterThan(0);
26+
});
27+
});

__tests__/simple-state.test.ts

+197
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
// @ts-nocheck
2+
import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing';
3+
import { assertIsDeliverTxSuccess } from '@cosmjs/stargate';
4+
5+
import path from "path";
6+
import fs from 'fs';
7+
import { getSigningJsdClient, jsd } from 'jsdjs'
8+
import { useChain, generateMnemonic } from 'starshipjs';
9+
import { sleep } from '../src/utils';
10+
import './setup.test';
11+
12+
describe('JSD tests', () => {
13+
let wallet, denom, address, queryClient, signingClient;
14+
let chainInfo, getCoin, getRpcEndpoint, creditFromFaucet;
15+
let contractCode, contractIndex;
16+
17+
beforeAll(async () => {
18+
({
19+
chainInfo,
20+
getCoin,
21+
getRpcEndpoint,
22+
creditFromFaucet
23+
} = useChain('jsd'));
24+
denom = (await getCoin()).base;
25+
26+
// Initialize wallet
27+
wallet = await DirectSecp256k1HdWallet.fromMnemonic(generateMnemonic(), {
28+
prefix: chainInfo.chain.bech32_prefix
29+
});
30+
address = (await wallet.getAccounts())[0].address;
31+
console.log(`contract creator address: ${address}`)
32+
33+
// Create custom cosmos interchain client
34+
queryClient = await jsd.ClientFactory.createRPCQueryClient({
35+
rpcEndpoint: await getRpcEndpoint()
36+
});
37+
38+
signingClient = await getSigningJsdClient({
39+
rpcEndpoint: await getRpcEndpoint(),
40+
signer: wallet
41+
});
42+
43+
await creditFromFaucet(address);
44+
await sleep(2000); // sleep for 1 sec to get tokens transferred from faucet successfully
45+
});
46+
47+
it('check balance', async () => {
48+
const balance = await signingClient.getBalance(address, denom);
49+
expect(balance.amount).toEqual("10000000000");
50+
expect(balance.denom).toEqual(denom);
51+
});
52+
53+
it('instantiate contract', async () => {
54+
// Read contract code from external file
55+
const contractPath = path.join(__dirname, '../contracts/simple-state.js');
56+
contractCode = fs.readFileSync(contractPath, 'utf8');
57+
58+
const fee = {
59+
amount: [
60+
{
61+
denom,
62+
amount: '100000'
63+
}
64+
],
65+
gas: '550000'
66+
};
67+
68+
const msg = jsd.jsd.MessageComposer.fromPartial.instantiate({
69+
creator: address,
70+
code: contractCode,
71+
});
72+
73+
const result = await signingClient.signAndBroadcast(address, [msg], fee);
74+
assertIsDeliverTxSuccess(result);
75+
76+
// Parse the response to get the contract index
77+
const response = jsd.jsd.MsgInstantiateResponse.fromProtoMsg(result.msgResponses[0]);
78+
contractIndex = response.index;
79+
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({index: contractIndex});
85+
expect(response.contracts.code).toEqual(contractCode);
86+
expect(response.contracts.index).toEqual(contractIndex);
87+
expect(response.contracts.creator).toEqual(address);
88+
});
89+
90+
it('query state before eval', async () => {
91+
const state = await queryClient.jsd.jsd.localState({index: contractIndex, key: "value"});
92+
expect(state).toEqual({value: ""});
93+
});
94+
95+
it('perform inc eval', async () => {
96+
const fee = {
97+
amount: [
98+
{
99+
denom,
100+
amount: '100000'
101+
}
102+
],
103+
gas: '550000'
104+
};
105+
106+
const msg = jsd.jsd.MessageComposer.fromPartial.eval({
107+
creator: address,
108+
index: contractIndex,
109+
fnName: "inc",
110+
arg: `{"x": 10}`,
111+
});
112+
113+
const result = await signingClient.signAndBroadcast(address, [msg], fee);
114+
assertIsDeliverTxSuccess(result);
115+
116+
const response = jsd.jsd.MsgEvalResponse.fromProtoMsg(result.msgResponses[0]);
117+
expect(response.result).toEqual("10");
118+
});
119+
120+
it('eval read from eval', async () => {
121+
const fee = {
122+
amount: [
123+
{
124+
denom,
125+
amount: '100000'
126+
}
127+
],
128+
gas: '550000'
129+
};
130+
131+
const msg = jsd.jsd.MessageComposer.fromPartial.eval({
132+
creator: address,
133+
index: contractIndex,
134+
fnName: "read",
135+
});
136+
137+
const result = await signingClient.signAndBroadcast(address, [msg], fee);
138+
assertIsDeliverTxSuccess(result);
139+
140+
const response = jsd.jsd.MsgEvalResponse.fromProtoMsg(result.msgResponses[0]);
141+
expect(response.result).toEqual("10");
142+
});
143+
144+
it('query state after eval', async () => {
145+
const state = await queryClient.jsd.jsd.localState({index: contractIndex, key: "value"});
146+
expect(state).toEqual({value: "10"});
147+
});
148+
149+
it('perform dec eval', async () => {
150+
const fee = {
151+
amount: [
152+
{
153+
denom,
154+
amount: '100000'
155+
}
156+
],
157+
gas: '550000'
158+
};
159+
160+
const msg = jsd.jsd.MessageComposer.fromPartial.eval({
161+
creator: address,
162+
index: contractIndex,
163+
fnName: "dec",
164+
arg: `{"x": 5}`,
165+
});
166+
167+
const result = await signingClient.signAndBroadcast(address, [msg], fee);
168+
assertIsDeliverTxSuccess(result);
169+
170+
const response = jsd.jsd.MsgEvalResponse.fromProtoMsg(result.msgResponses[0]);
171+
expect(response.result).toEqual("5");
172+
});
173+
174+
it('eval read from eval', async () => {
175+
const fee = {
176+
amount: [
177+
{
178+
denom,
179+
amount: '100000'
180+
}
181+
],
182+
gas: '550000'
183+
};
184+
185+
const msg = jsd.jsd.MessageComposer.fromPartial.eval({
186+
creator: address,
187+
index: contractIndex,
188+
fnName: "read",
189+
});
190+
191+
const result = await signingClient.signAndBroadcast(address, [msg], fee);
192+
assertIsDeliverTxSuccess(result);
193+
194+
const response = jsd.jsd.MsgEvalResponse.fromProtoMsg(result.msgResponses[0]);
195+
expect(response.result).toEqual("5");
196+
});
197+
});

configs/ci.yaml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: starship-devnet
2+
version: 0.2.14
3+
4+
chains:
5+
- id: jsd
6+
name: custom
7+
numValidators: 1
8+
image: ghcr.io/cosmology-tech/jsd:latest
9+
home: /root/.jsd
10+
binary: jsdd
11+
prefix: cosmos
12+
denom: stake
13+
coins: 100000000000000stake
14+
hdPath: m/44'/118'/0'/0/0
15+
coinType: 118
16+
repo: https://github.com/cosmology-tech/jsd
17+
ports:
18+
rest: 1313
19+
rpc: 26653
20+
faucet: 8003
21+
resources:
22+
cpu: "0.4"
23+
memory: "400M"
24+
faucet:
25+
enabled: true
26+
type: starship
27+
resources:
28+
cpu: "0.1"
29+
memory: "100M"
30+
31+
registry:
32+
enabled: true
33+
ports:
34+
rest: 8081
35+
resources:
36+
cpu: "0.1"
37+
memory: "100M"

configs/local.yaml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: starship-devnet
2+
version: 0.2.14
3+
4+
chains:
5+
- id: jsd
6+
name: custom
7+
numValidators: 1
8+
image: ghcr.io/cosmology-tech/jsd:latest
9+
home: /root/.jsd
10+
binary: jsdd
11+
prefix: cosmos
12+
denom: stake
13+
coins: 100000000000000stake
14+
hdPath: m/44'/118'/0'/0/0
15+
coinType: 118
16+
repo: https://github.com/cosmology-tech/jsd
17+
ports:
18+
rest: 1313
19+
rpc: 26653
20+
faucet: 8003
21+
faucet:
22+
enabled: true
23+
type: starship
24+
## test accounts, add more accounts as needed
25+
balances:
26+
- address: cosmos1e9ucjn5fjmetky5wezzcsccp7hqcwzrrhthpf5
27+
amount: "2000000000000stake"
28+
- address: cosmos10eykchznjdn8jdlwaj5v9wvlmdsp6kxx7u0hv9
29+
amount: "2000000000000stake"
30+
31+
registry:
32+
enabled: true
33+
ports:
34+
rest: 8081
35+
36+
explorer:
37+
enabled: false
38+
ports:
39+
rest: 8080
40+
41+
images:
42+
imagePullPolicy: Always

0 commit comments

Comments
 (0)