From 62cd7f12e3509442b7fbae98026eef068792d64f Mon Sep 17 00:00:00 2001 From: jovonni Date: Sat, 22 Mar 2025 23:24:41 -0400 Subject: [PATCH 01/13] chore(build): fixed merge conflict --- templates/hyperweb/scripts/build.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/hyperweb/scripts/build.ts b/templates/hyperweb/scripts/build.ts index ee19a2a0..0116516a 100644 --- a/templates/hyperweb/scripts/build.ts +++ b/templates/hyperweb/scripts/build.ts @@ -3,7 +3,7 @@ import { join } from "path"; import { configs, type BuildConfig } from "./configs"; -const rootDir = join(__dirname, "/../"); +const rootDir = join(__dirname, '/../'); async function buildInterweb(config: BuildConfig): Promise { const { entryFile, outFile, externalPackages } = config; From 8cfada686e7ec0de0332ee54cfe4250aa4d40158 Mon Sep 17 00:00:00 2001 From: jovonni Date: Thu, 20 Feb 2025 17:35:22 -0500 Subject: [PATCH 02/13] feat(hello): added hello world contract --- templates/hyperweb/src/hello/index.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 templates/hyperweb/src/hello/index.ts diff --git a/templates/hyperweb/src/hello/index.ts b/templates/hyperweb/src/hello/index.ts new file mode 100644 index 00000000..af2578b7 --- /dev/null +++ b/templates/hyperweb/src/hello/index.ts @@ -0,0 +1,12 @@ +export default class Contract { + state: { + msg?: string | boolean | null; + } = {}; + + constructor() { } + + hello(x: string) { + this.state.msg = x; + return `Hello, ${String(this.state.msg)}`; + } +} From 600f3443266ad3863e27eb82774a7c4456bcf81b Mon Sep 17 00:00:00 2001 From: jovonni Date: Thu, 20 Feb 2025 17:46:28 -0500 Subject: [PATCH 03/13] chore(hello): remove default value --- templates/hyperweb/src/hello/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/hyperweb/src/hello/index.ts b/templates/hyperweb/src/hello/index.ts index af2578b7..6aa32ae8 100644 --- a/templates/hyperweb/src/hello/index.ts +++ b/templates/hyperweb/src/hello/index.ts @@ -1,7 +1,7 @@ export default class Contract { state: { msg?: string | boolean | null; - } = {}; + }; constructor() { } From 2bb59c06afb79016c332c4c7e489f3180dd7d891 Mon Sep 17 00:00:00 2001 From: jovonni Date: Fri, 21 Feb 2025 10:18:53 -0500 Subject: [PATCH 04/13] feat(bank): add bank contract --- templates/hyperweb/src/bank/index.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 templates/hyperweb/src/bank/index.ts diff --git a/templates/hyperweb/src/bank/index.ts b/templates/hyperweb/src/bank/index.ts new file mode 100644 index 00000000..b9f5374a --- /dev/null +++ b/templates/hyperweb/src/bank/index.ts @@ -0,0 +1,20 @@ +// @ts-ignore +import { getBalance, sendCoins } from "@hyperweb/bank"; + +export default class Contract { + constructor() { } + + balance({ address, denom }: { address: string; denom: string }): string { + return getBalance(address, denom).amount.toString(); + } + + transfer({ from, to, amount, denom }: { + from: string; + to: string; + amount: number; + denom: string + }): string { + sendCoins(from, to, { [denom]: amount }); + return "Transfer successful"; + } +} \ No newline at end of file From 6c7fe138dad796a8d71e0dc63a8ac7eac8b78a2e Mon Sep 17 00:00:00 2001 From: jovonni Date: Fri, 21 Feb 2025 10:19:36 -0500 Subject: [PATCH 05/13] feat(factory): added token factory contract --- templates/hyperweb/src/token-factory/index.ts | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 templates/hyperweb/src/token-factory/index.ts diff --git a/templates/hyperweb/src/token-factory/index.ts b/templates/hyperweb/src/token-factory/index.ts new file mode 100644 index 00000000..4414135e --- /dev/null +++ b/templates/hyperweb/src/token-factory/index.ts @@ -0,0 +1,37 @@ +// @ts-ignore +import { createDenom, mintTokens, burnTokens } from '@hyperweb/token'; +// @ts-ignore +import { getBalance } from '@hyperweb/bank'; + +export default class Contract { + private msg: { sender: string }; + constructor() { } + + createDenom({ denom }: { denom: string }) { + console.log("denom:", denom); + const token = createDenom(this.msg.sender, denom); + console.log("created token:", token); + return token; + } + + mintTokens({ denom, amount }: { denom: string; amount: number }) { + console.log("minting tokens:", amount, "of", denom); + const minted = mintTokens(this.msg.sender, denom, amount); + console.log("minted:", minted); + return minted; + } + + burnTokens({ denom, amount }: { denom: string; amount: number }) { + console.log("burning tokens:", amount, "of", denom); + const burned = burnTokens(this.msg.sender, denom, amount); + console.log("burned:", burned); + return burned; + } + + getBalance({ address, denom }: { address: string; denom: string }) { + console.log("checking balance for address:", address, "denom:", denom); + const balance = getBalance(address, denom); + console.log("balance:", balance.amount); + return balance.amount; + } +} From d4c48e45c6a6bc44482bb9a87acf6647ceda9d4d Mon Sep 17 00:00:00 2001 From: jovonni Date: Sun, 23 Mar 2025 00:43:41 -0400 Subject: [PATCH 06/13] chore(simpleState): rename simple state --- .../hyperweb/__tests__/simpleState.test.ts | 189 ------------------ .../hyperweb/dist/contracts/simpleState.js | 33 --- .../dist/contracts/simpleState.js.map | 7 - 3 files changed, 229 deletions(-) delete mode 100644 templates/hyperweb/__tests__/simpleState.test.ts delete mode 100644 templates/hyperweb/dist/contracts/simpleState.js delete mode 100644 templates/hyperweb/dist/contracts/simpleState.js.map diff --git a/templates/hyperweb/__tests__/simpleState.test.ts b/templates/hyperweb/__tests__/simpleState.test.ts deleted file mode 100644 index f8e47a3f..00000000 --- a/templates/hyperweb/__tests__/simpleState.test.ts +++ /dev/null @@ -1,189 +0,0 @@ -// @ts-nocheck -import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing'; -import { assertIsDeliverTxSuccess } from '@cosmjs/stargate'; - -import path from "path"; -import fs from 'fs'; -import { getSigningHyperwebClient, hyperweb, google } from 'hyperwebjs'; -import { useChain, generateMnemonic } from 'starshipjs'; -import { sleep } from '../test-utils/sleep'; -import './setup.test'; - -describe('State Contract Tests', () => { - let wallet, denom, address, queryClient, signingClient; - let chainInfo, getCoin, getRpcEndpoint, creditFromFaucet; - let contractCode, contractIndex, contractAddress; - let fee; - - beforeAll(async () => { - ({ - chainInfo, - getCoin, - getRpcEndpoint, - creditFromFaucet - } = useChain('hyperweb')); - - denom = (await getCoin()).base; - - // Initialize wallet - wallet = await DirectSecp256k1HdWallet.fromMnemonic(generateMnemonic(), { - prefix: chainInfo.chain.bech32_prefix - }); - address = (await wallet.getAccounts())[0].address; - console.log(`Contract creator address: ${address}`); - - // Create custom cosmos interchain client - queryClient = await hyperweb.ClientFactory.createRPCQueryClient({ - rpcEndpoint: await getRpcEndpoint() - }); - - signingClient = await getSigningHyperwebClient({ - rpcEndpoint: await getRpcEndpoint(), - signer: wallet - }); - - // Set default transaction fee - fee = { amount: [{ denom, amount: '100000' }], gas: '550000' }; - - await creditFromFaucet(address); - await sleep(2000); // Sleep for 2 sec to allow faucet tokens to arrive - }); - - it('Check initial balance', async () => { - const balance = await signingClient.getBalance(address, denom); - expect(balance.amount).toEqual("10000000000"); - expect(balance.denom).toEqual(denom); - }); - - it('Instantiate state contract', async () => { - // Read contract code from external file - const contractPath = path.join( - __dirname, - "../dist/contracts/simpleState.js" - ); - contractCode = fs.readFileSync(contractPath, "utf8"); - - const msg = hyperweb.hvm.MessageComposer.fromPartial.instantiate({ - creator: address, - code: contractCode, - source: "test_source", - }); - - const result = await signingClient.signAndBroadcast(address, [msg], fee); - assertIsDeliverTxSuccess(result); - - // Parse the response to get the contract index - const response = hyperweb.hvm.MsgInstantiateResponse.fromProtoMsg(result.msgResponses[0]); - contractIndex = response.index; - contractAddress = response.address; - expect(contractIndex).toBeGreaterThan(0); - console.log(`Contract instantiated at index: ${contractIndex} and address ${contractAddress}`); - }); - - it('Perform init function', async () => { - const msg = hyperweb.hvm.MessageComposer.fromPartial.eval({ - address: contractAddress, - creator: address, - callee: "init", - args: [] - }); - - const result = await signingClient.signAndBroadcast(address, [msg], fee); - assertIsDeliverTxSuccess(result); - - const response = hyperweb.hvm.MsgEvalResponse.fromProtoMsg(result.msgResponses[0]); - expect(response.result).toEqual("0"); - }); - - it('Perform increment evaluation', async () => { - const msg = hyperweb.hvm.MessageComposer.fromPartial.eval({ - address: contractAddress, - creator: address, - callee: "inc", - args: ["10"] - }); - - const result = await signingClient.signAndBroadcast(address, [msg], fee); - assertIsDeliverTxSuccess(result); - - const response = hyperweb.hvm.MsgEvalResponse.fromProtoMsg(result.msgResponses[0]); - expect(response.result).toEqual("10"); - }); - // - // it('Perform decrement evaluation', async () => { - // const msg = hyperweb.hvm.MessageComposer.fromPartial.eval({ - // creator: address, - // callee: "dec", - // index: contractIndex, - // args: [] - // }); - // - // const result = await signingClient.signAndBroadcast(address, [msg], fee); - // assertIsDeliverTxSuccess(result); - // - // const response = hyperweb.hvm.MsgEvalResponse.fromProtoMsg(result.msgResponses[0]); - // expect(response.result).toEqual("0"); - // }); - // - // it('Perform multiple increments and verify state', async () => { - // for (let i = 0; i < 3; i++) { - // const msg = hyperweb.hvm.MessageComposer.fromPartial.eval({ - // creator: address, - // callee: "inc", - // index: contractIndex, - // args: [] - // }); - // - // const result = await signingClient.signAndBroadcast(address, [msg], fee); - // assertIsDeliverTxSuccess(result); - // } - // - // const msgRead = hyperweb.hvm.MessageComposer.fromPartial.eval({ - // creator: address, - // callee: "read", - // index: contractIndex, - // args: [] - // }); - // - // const result = await signingClient.signAndBroadcast(address, [msgRead], fee); - // assertIsDeliverTxSuccess(result); - // - // const response = hyperweb.hvm.MsgEvalResponse.fromProtoMsg(result.msgResponses[0]); - // expect(response.result).toEqual("3"); - // }); - // - // it('Perform reset and verify state', async () => { - // const msg = hyperweb.hvm.MessageComposer.fromPartial.eval({ - // creator: address, - // callee: "reset", - // index: contractIndex, - // args: [] - // }); - // - // const result = await signingClient.signAndBroadcast(address, [msg], fee); - // assertIsDeliverTxSuccess(result); - // - // const response = hyperweb.hvm.MsgEvalResponse.fromProtoMsg(result.msgResponses[0]); - // expect(response.result).toEqual("0"); - // }); - // - // it('Verify read function returns the correct state value', async () => { - // const msg = hyperweb.hvm.MessageComposer.fromPartial.eval({ - // creator: address, - // callee: "read", - // index: contractIndex, - // args: [] - // }); - // - // const result = await signingClient.signAndBroadcast(address, [msg], fee); - // assertIsDeliverTxSuccess(result); - // - // const response = hyperweb.hvm.MsgEvalResponse.fromProtoMsg(result.msgResponses[0]); - // expect(response.result).toEqual("0"); - // }); - // - // it('Retrieve contract source and validate', async () => { - // const contractSource = await queryClient.hyperweb.hvm.getContractSource({ index: contractIndex }); - // expect(contractSource.source).toEqual("test_source"); - // }); -}); diff --git a/templates/hyperweb/dist/contracts/simpleState.js b/templates/hyperweb/dist/contracts/simpleState.js deleted file mode 100644 index f4fc89dd..00000000 --- a/templates/hyperweb/dist/contracts/simpleState.js +++ /dev/null @@ -1,33 +0,0 @@ -// src/simple-state/index.ts -var Contract = class { - state; - constructor() { - console.log("[Contract] constructor called"); - } - reset() { - console.log("[Contract] reset called"); - this.state.value = 0; - } - init() { - console.log("[Contract] init called"); - this.state.value = 0; - return this.state.value; - } - inc(x) { - console.log("[Contract] inc called"); - this.state.value += x; - return this.state.value; - } - dec(x) { - console.log("[Contract] dec called"); - this.state.value -= x; - } - read() { - console.log("[Contract] read called"); - return this.state.value; - } -}; -export { - Contract as default -}; -//# sourceMappingURL=simpleState.js.map diff --git a/templates/hyperweb/dist/contracts/simpleState.js.map b/templates/hyperweb/dist/contracts/simpleState.js.map deleted file mode 100644 index 99d5867a..00000000 --- a/templates/hyperweb/dist/contracts/simpleState.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../../src/simple-state/index.ts"], - "sourcesContent": ["export interface State {\n value: number;\n}\n\nexport default class Contract {\n state: State;\n\n constructor() {\n console.log(\"[Contract] constructor called\");\n }\n\n reset() {\n console.log(\"[Contract] reset called\");\n this.state.value = 0;\n }\n\n init(): number {\n console.log(\"[Contract] init called\");\n this.state.value = 0;\n return this.state.value\n }\n\n inc(x: number): number {\n console.log(\"[Contract] inc called\");\n this.state.value += x;\n return this.state.value;\n }\n\n dec(x: number) {\n console.log(\"[Contract] dec called\");\n this.state.value -= x;\n }\n\n read() {\n console.log(\"[Contract] read called\");\n return this.state.value;\n }\n}\n"], - "mappings": ";AAIA,IAAqB,WAArB,MAA8B;AAAA,EAC5B;AAAA,EAEA,cAAc;AACZ,YAAQ,IAAI,+BAA+B;AAAA,EAC7C;AAAA,EAEA,QAAQ;AACN,YAAQ,IAAI,yBAAyB;AACrC,SAAK,MAAM,QAAQ;AAAA,EACrB;AAAA,EAEA,OAAe;AACb,YAAQ,IAAI,wBAAwB;AACpC,SAAK,MAAM,QAAQ;AACnB,WAAO,KAAK,MAAM;AAAA,EACpB;AAAA,EAEA,IAAI,GAAmB;AACrB,YAAQ,IAAI,uBAAuB;AACnC,SAAK,MAAM,SAAS;AACpB,WAAO,KAAK,MAAM;AAAA,EACpB;AAAA,EAEA,IAAI,GAAW;AACb,YAAQ,IAAI,uBAAuB;AACnC,SAAK,MAAM,SAAS;AAAA,EACtB;AAAA,EAEA,OAAO;AACL,YAAQ,IAAI,wBAAwB;AACpC,WAAO,KAAK,MAAM;AAAA,EACpB;AACF;", - "names": [] -} From 8fc22f0a42c0cec0dd5fc4bca3793193cd720dda Mon Sep 17 00:00:00 2001 From: jovonni Date: Sun, 23 Mar 2025 00:44:22 -0400 Subject: [PATCH 07/13] chore(config): added bank, token factory, and hello contracts to build config --- templates/hyperweb/scripts/configs.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/templates/hyperweb/scripts/configs.ts b/templates/hyperweb/scripts/configs.ts index 08f057ec..ee5d241a 100644 --- a/templates/hyperweb/scripts/configs.ts +++ b/templates/hyperweb/scripts/configs.ts @@ -5,9 +5,26 @@ export interface BuildConfig { } export const configs: BuildConfig[] = [ + { + entryFile: "src/hello/index.ts", + outFile: "dist/contracts/hello.js", + externalPackages: ["otherpackage", "~somepackage"], + }, { entryFile: "src/simple-state/index.ts", - outFile: "dist/contracts/simpleState.js", + outFile: "dist/contracts/simple-state.js", externalPackages: ["otherpackage", "~somepackage"], }, + { + entryFile: "src/bank/index.ts", + outFile: "dist/contracts/bank.js", + externalPackages: ["@hyperweb/bank"], + }, + { + entryFile: "src/token-factory/index.ts", + outFile: "dist/contracts/token-factory.js", + externalPackages: ["@hyperweb/token", "@hyperweb/bank"], + }, + + ]; From 27648839a8b8b9704d8287e4ffd86b4be5e40b76 Mon Sep 17 00:00:00 2001 From: jovonni Date: Sun, 23 Mar 2025 00:44:58 -0400 Subject: [PATCH 08/13] contract(bank): added logs, and fixed denom usage --- templates/hyperweb/src/bank/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/templates/hyperweb/src/bank/index.ts b/templates/hyperweb/src/bank/index.ts index b9f5374a..96776074 100644 --- a/templates/hyperweb/src/bank/index.ts +++ b/templates/hyperweb/src/bank/index.ts @@ -5,6 +5,7 @@ export default class Contract { constructor() { } balance({ address, denom }: { address: string; denom: string }): string { + console.log("checking balance for address:", address, "denom:", denom); return getBalance(address, denom).amount.toString(); } @@ -14,7 +15,8 @@ export default class Contract { amount: number; denom: string }): string { - sendCoins(from, to, { [denom]: amount }); + console.log("transferring", amount, "of", denom, "from", from, "to", to); + sendCoins(from, to, `${amount}${denom}`); return "Transfer successful"; } } \ No newline at end of file From 0a0575223ed4611e0009a4606babea8942de016b Mon Sep 17 00:00:00 2001 From: jovonni Date: Sun, 23 Mar 2025 00:45:23 -0400 Subject: [PATCH 09/13] test(bank): added bank contract tests --- templates/hyperweb/__tests__/bank.test.ts | 134 ++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 templates/hyperweb/__tests__/bank.test.ts diff --git a/templates/hyperweb/__tests__/bank.test.ts b/templates/hyperweb/__tests__/bank.test.ts new file mode 100644 index 00000000..ce7a555e --- /dev/null +++ b/templates/hyperweb/__tests__/bank.test.ts @@ -0,0 +1,134 @@ +// @ts-nocheck +import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing'; +import { assertIsDeliverTxSuccess } from '@cosmjs/stargate'; + +import path from "path"; +import fs from 'fs'; +import { getSigningHyperwebClient, hyperweb, google } from 'hyperwebjs'; +import { useChain, generateMnemonic } from 'starshipjs'; +import { sleep } from '../test-utils/sleep'; +import './setup.test'; + +describe('Bank Contract Tests', () => { + let wallet, denom, address, queryClient, signingClient; + let chainInfo, getCoin, getRpcEndpoint, creditFromFaucet; + let contractCode, contractIndex, contractAddress; + let fee; + let recipientWallet, recipientAddress; + + beforeAll(async () => { + ({ + chainInfo, + getCoin, + getRpcEndpoint, + creditFromFaucet + } = useChain('hyperweb')); + + denom = (await getCoin()).base; + + wallet = await DirectSecp256k1HdWallet.fromMnemonic(generateMnemonic(), { + prefix: chainInfo.chain.bech32_prefix + }); + address = (await wallet.getAccounts())[0].address; + console.log(`contract creator address: ${address}`); + + recipientWallet = await DirectSecp256k1HdWallet.fromMnemonic(generateMnemonic(), { + prefix: chainInfo.chain.bech32_prefix + }); + recipientAddress = (await recipientWallet.getAccounts())[0].address; + console.log(`recipient address: ${recipientAddress}`); + + queryClient = await hyperweb.ClientFactory.createRPCQueryClient({ + rpcEndpoint: await getRpcEndpoint() + }); + + signingClient = await getSigningHyperwebClient({ + rpcEndpoint: await getRpcEndpoint(), + signer: wallet + }); + + fee = { amount: [{ denom, amount: '100000' }], gas: '550000' }; + + await creditFromFaucet(address); + await sleep(10000); + }); + + it('Check initial balance', async () => { + const balance = await signingClient.getBalance(address, denom); + expect(balance.amount).toEqual("10000000000"); + expect(balance.denom).toEqual(denom); + }); + + it('Instantiate Bank contract', async () => { + const contractPath = path.join( + __dirname, + "../dist/contracts/bank.js" + ); + contractCode = fs.readFileSync(contractPath, "utf8"); + + const msg = hyperweb.hvm.MessageComposer.fromPartial.instantiate({ + creator: address, + code: contractCode, + source: "test_source", + }); + + const result = await signingClient.signAndBroadcast(address, [msg], fee); + assertIsDeliverTxSuccess(result); + + const response = hyperweb.hvm.MsgInstantiateResponse.fromProtoMsg(result.msgResponses[0]); + contractIndex = response.index; + contractAddress = response.address; + expect(contractIndex).toBeGreaterThan(0); + console.log(`contract instantiated at index: ${contractIndex} and address ${contractAddress}`); + }); + + it('Call balance function', async () => { + const args = JSON.stringify({ address, denom }); + const msg = hyperweb.hvm.MessageComposer.fromPartial.eval({ + address: contractAddress, + creator: address, + callee: "balance", + args: [args] + }); + + const result = await signingClient.signAndBroadcast(address, [msg], fee); + assertIsDeliverTxSuccess(result); + + const response = hyperweb.hvm.MsgEvalResponse.fromProtoMsg(result.msgResponses[0]); + expect(parseInt(response.result)).toBeGreaterThanOrEqual(0); + }); + + it('Transfer funds to another address and check balance', async () => { + const transferArgs = JSON.stringify({ + from: address, + to: recipientAddress, + amount: 1000, + denom + }); + const transferMsg = hyperweb.hvm.MessageComposer.fromPartial.eval({ + address: contractAddress, + creator: address, + callee: "transfer", + args: [transferArgs] + }); + + const transferResult = await signingClient.signAndBroadcast(address, [transferMsg], fee); + assertIsDeliverTxSuccess(transferResult); + + const checkArgs = JSON.stringify({ address: recipientAddress, denom }); + const checkMsg = hyperweb.hvm.MessageComposer.fromPartial.eval({ + address: contractAddress, + creator: address, + callee: "balance", + args: [checkArgs] + }); + + const checkResult = await signingClient.signAndBroadcast(address, [checkMsg], fee); + assertIsDeliverTxSuccess(checkResult); + + const checkResponse = hyperweb.hvm.MsgEvalResponse.fromProtoMsg(checkResult.msgResponses[0]); + console.log(`recipient balance: ${checkResponse.result}`); + expect(parseInt(checkResponse.result)).toBeGreaterThanOrEqual(1000); + }); + +}); From d685818269f20330a33ee33202c2515601ea5865 Mon Sep 17 00:00:00 2001 From: jovonni Date: Sun, 23 Mar 2025 00:45:42 -0400 Subject: [PATCH 10/13] test(hello): added hello contract tests --- templates/hyperweb/__tests__/hello.test.ts | 93 ++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 templates/hyperweb/__tests__/hello.test.ts diff --git a/templates/hyperweb/__tests__/hello.test.ts b/templates/hyperweb/__tests__/hello.test.ts new file mode 100644 index 00000000..6a8f3985 --- /dev/null +++ b/templates/hyperweb/__tests__/hello.test.ts @@ -0,0 +1,93 @@ +// @ts-nocheck +import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing'; +import { assertIsDeliverTxSuccess } from '@cosmjs/stargate'; + +import path from "path"; +import fs from 'fs'; +import { getSigningHyperwebClient, hyperweb, google } from 'hyperwebjs'; +import { useChain, generateMnemonic } from 'starshipjs'; +import { sleep } from '../test-utils/sleep'; +import './setup.test'; + +describe('Hello Contract Tests', () => { + let wallet, denom, address, queryClient, signingClient; + let chainInfo, getCoin, getRpcEndpoint, creditFromFaucet; + let contractCode, contractIndex, contractAddress; + let fee; + + beforeAll(async () => { + ({ + chainInfo, + getCoin, + getRpcEndpoint, + creditFromFaucet + } = useChain('hyperweb')); + + denom = (await getCoin()).base; + + wallet = await DirectSecp256k1HdWallet.fromMnemonic(generateMnemonic(), { + prefix: chainInfo.chain.bech32_prefix + }); + address = (await wallet.getAccounts())[0].address; + console.log(`Contract creator address: ${address}`); + + queryClient = await hyperweb.ClientFactory.createRPCQueryClient({ + rpcEndpoint: await getRpcEndpoint() + }); + + signingClient = await getSigningHyperwebClient({ + rpcEndpoint: await getRpcEndpoint(), + signer: wallet + }); + + fee = { amount: [{ denom, amount: '100000' }], gas: '550000' }; + + await creditFromFaucet(address); + await sleep(10000); + }); + + it('Check initial balance', async () => { + const balance = await signingClient.getBalance(address, denom); + expect(balance.amount).toEqual("10000000000"); + expect(balance.denom).toEqual(denom); + }); + + it('Instantiate hello contract', async () => { + const contractPath = path.join( + __dirname, + "../dist/contracts/hello.js" + ); + contractCode = fs.readFileSync(contractPath, "utf8"); + + const msg = hyperweb.hvm.MessageComposer.fromPartial.instantiate({ + creator: address, + code: contractCode, + source: "test_source", + }); + + const result = await signingClient.signAndBroadcast(address, [msg], fee); + assertIsDeliverTxSuccess(result); + + const response = hyperweb.hvm.MsgInstantiateResponse.fromProtoMsg(result.msgResponses[0]); + contractIndex = response.index; + contractAddress = response.address; + expect(contractIndex).toBeGreaterThan(0); + console.log(`contract instantiated at index: ${contractIndex} and address ${contractAddress}`); + }); + + it('Invoke hello function', async () => { + const msg = hyperweb.hvm.MessageComposer.fromPartial.eval({ + address: contractAddress, + creator: address, + callee: "hello", + args: [JSON.stringify("World")] + }); + + const result = await signingClient.signAndBroadcast(address, [msg], fee); + assertIsDeliverTxSuccess(result); + + const response = hyperweb.hvm.MsgEvalResponse.fromProtoMsg(result.msgResponses[0]); + expect(response.result).toEqual("Hello, World"); + }); + +}); From 30df011598bcfab407d1593fb825fc0de4bacad9 Mon Sep 17 00:00:00 2001 From: jovonni Date: Sun, 23 Mar 2025 00:46:46 -0400 Subject: [PATCH 11/13] test(simple-state): rename simple-state contract tests --- .../hyperweb/__tests__/simple-state.test.ts | 189 ++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 templates/hyperweb/__tests__/simple-state.test.ts diff --git a/templates/hyperweb/__tests__/simple-state.test.ts b/templates/hyperweb/__tests__/simple-state.test.ts new file mode 100644 index 00000000..3d88feb0 --- /dev/null +++ b/templates/hyperweb/__tests__/simple-state.test.ts @@ -0,0 +1,189 @@ +// @ts-nocheck +import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing'; +import { assertIsDeliverTxSuccess } from '@cosmjs/stargate'; + +import path from "path"; +import fs from 'fs'; +import { getSigningHyperwebClient, hyperweb, google } from 'hyperwebjs'; +import { useChain, generateMnemonic } from 'starshipjs'; +import { sleep } from '../test-utils/sleep'; +import './setup.test'; + +describe('State Contract Tests', () => { + let wallet, denom, address, queryClient, signingClient; + let chainInfo, getCoin, getRpcEndpoint, creditFromFaucet; + let contractCode, contractIndex, contractAddress; + let fee; + + beforeAll(async () => { + ({ + chainInfo, + getCoin, + getRpcEndpoint, + creditFromFaucet + } = useChain('hyperweb')); + + denom = (await getCoin()).base; + + // Initialize wallet + wallet = await DirectSecp256k1HdWallet.fromMnemonic(generateMnemonic(), { + prefix: chainInfo.chain.bech32_prefix + }); + address = (await wallet.getAccounts())[0].address; + console.log(`Contract creator address: ${address}`); + + // Create custom cosmos interchain client + queryClient = await hyperweb.ClientFactory.createRPCQueryClient({ + rpcEndpoint: await getRpcEndpoint() + }); + + signingClient = await getSigningHyperwebClient({ + rpcEndpoint: await getRpcEndpoint(), + signer: wallet + }); + + // Set default transaction fee + fee = { amount: [{ denom, amount: '100000' }], gas: '550000' }; + + await creditFromFaucet(address); + await sleep(10000); // Sleep for 2 sec to allow faucet tokens to arrive + }); + + it('Check initial balance', async () => { + const balance = await signingClient.getBalance(address, denom); + expect(balance.amount).toEqual("10000000000"); + expect(balance.denom).toEqual(denom); + }); + + it('Instantiate state contract', async () => { + // Read contract code from external file + const contractPath = path.join( + __dirname, + "../dist/contracts/simple-state.js" + ); + contractCode = fs.readFileSync(contractPath, "utf8"); + + const msg = hyperweb.hvm.MessageComposer.fromPartial.instantiate({ + creator: address, + code: contractCode, + source: "test_source", + }); + + const result = await signingClient.signAndBroadcast(address, [msg], fee); + assertIsDeliverTxSuccess(result); + + // Parse the response to get the contract index + const response = hyperweb.hvm.MsgInstantiateResponse.fromProtoMsg(result.msgResponses[0]); + contractIndex = response.index; + contractAddress = response.address; + expect(contractIndex).toBeGreaterThan(0); + console.log(`Contract instantiated at index: ${contractIndex} and address ${contractAddress}`); + }); + + it('Perform init function', async () => { + const msg = hyperweb.hvm.MessageComposer.fromPartial.eval({ + address: contractAddress, + creator: address, + callee: "init", + args: [] + }); + + const result = await signingClient.signAndBroadcast(address, [msg], fee); + assertIsDeliverTxSuccess(result); + + const response = hyperweb.hvm.MsgEvalResponse.fromProtoMsg(result.msgResponses[0]); + expect(response.result).toEqual("0"); + }); + + it('Perform increment evaluation', async () => { + const msg = hyperweb.hvm.MessageComposer.fromPartial.eval({ + address: contractAddress, + creator: address, + callee: "inc", + args: ["10"] + }); + + const result = await signingClient.signAndBroadcast(address, [msg], fee); + assertIsDeliverTxSuccess(result); + + const response = hyperweb.hvm.MsgEvalResponse.fromProtoMsg(result.msgResponses[0]); + expect(response.result).toEqual("10"); + }); + // + // it('Perform decrement evaluation', async () => { + // const msg = hyperweb.hvm.MessageComposer.fromPartial.eval({ + // creator: address, + // callee: "dec", + // index: contractIndex, + // args: [] + // }); + // + // const result = await signingClient.signAndBroadcast(address, [msg], fee); + // assertIsDeliverTxSuccess(result); + // + // const response = hyperweb.hvm.MsgEvalResponse.fromProtoMsg(result.msgResponses[0]); + // expect(response.result).toEqual("0"); + // }); + // + // it('Perform multiple increments and verify state', async () => { + // for (let i = 0; i < 3; i++) { + // const msg = hyperweb.hvm.MessageComposer.fromPartial.eval({ + // creator: address, + // callee: "inc", + // index: contractIndex, + // args: [] + // }); + // + // const result = await signingClient.signAndBroadcast(address, [msg], fee); + // assertIsDeliverTxSuccess(result); + // } + // + // const msgRead = hyperweb.hvm.MessageComposer.fromPartial.eval({ + // creator: address, + // callee: "read", + // index: contractIndex, + // args: [] + // }); + // + // const result = await signingClient.signAndBroadcast(address, [msgRead], fee); + // assertIsDeliverTxSuccess(result); + // + // const response = hyperweb.hvm.MsgEvalResponse.fromProtoMsg(result.msgResponses[0]); + // expect(response.result).toEqual("3"); + // }); + // + // it('Perform reset and verify state', async () => { + // const msg = hyperweb.hvm.MessageComposer.fromPartial.eval({ + // creator: address, + // callee: "reset", + // index: contractIndex, + // args: [] + // }); + // + // const result = await signingClient.signAndBroadcast(address, [msg], fee); + // assertIsDeliverTxSuccess(result); + // + // const response = hyperweb.hvm.MsgEvalResponse.fromProtoMsg(result.msgResponses[0]); + // expect(response.result).toEqual("0"); + // }); + // + // it('Verify read function returns the correct state value', async () => { + // const msg = hyperweb.hvm.MessageComposer.fromPartial.eval({ + // creator: address, + // callee: "read", + // index: contractIndex, + // args: [] + // }); + // + // const result = await signingClient.signAndBroadcast(address, [msg], fee); + // assertIsDeliverTxSuccess(result); + // + // const response = hyperweb.hvm.MsgEvalResponse.fromProtoMsg(result.msgResponses[0]); + // expect(response.result).toEqual("0"); + // }); + // + // it('Retrieve contract source and validate', async () => { + // const contractSource = await queryClient.hyperweb.hvm.getContractSource({ index: contractIndex }); + // expect(contractSource.source).toEqual("test_source"); + // }); +}); From 20eb2a6f41c3b2473390e745f68021b478c3478f Mon Sep 17 00:00:00 2001 From: jovonni Date: Sun, 23 Mar 2025 00:47:14 -0400 Subject: [PATCH 12/13] test(token-factory): added token factory tests --- .../hyperweb/__tests__/token-factory.test.ts | 128 ++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 templates/hyperweb/__tests__/token-factory.test.ts diff --git a/templates/hyperweb/__tests__/token-factory.test.ts b/templates/hyperweb/__tests__/token-factory.test.ts new file mode 100644 index 00000000..c5a31bd8 --- /dev/null +++ b/templates/hyperweb/__tests__/token-factory.test.ts @@ -0,0 +1,128 @@ +// @ts-nocheck +import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing'; +import { assertIsDeliverTxSuccess } from '@cosmjs/stargate'; + +import path from "path"; +import fs from 'fs'; +import { getSigningHyperwebClient, hyperweb, google } from 'hyperwebjs'; +import { useChain, generateMnemonic } from 'starshipjs'; +import { sleep } from '../test-utils/sleep'; +import './setup.test'; + +describe('Token Factory Contract Tests', () => { + let wallet, denom, address, queryClient, signingClient; + let chainInfo, getCoin, getRpcEndpoint, creditFromFaucet; + let contractCode, contractIndex, contractAddress; + let fee; + let fullDenom: string; + + + beforeAll(async () => { + ({ + chainInfo, + getCoin, + getRpcEndpoint, + creditFromFaucet + } = useChain('hyperweb')); + + denom = (await getCoin()).base; + + wallet = await DirectSecp256k1HdWallet.fromMnemonic(generateMnemonic(), { + prefix: chainInfo.chain.bech32_prefix + }); + address = (await wallet.getAccounts())[0].address; + console.log(`contract creator address: ${address}`); + + queryClient = await hyperweb.ClientFactory.createRPCQueryClient({ + rpcEndpoint: await getRpcEndpoint() + }); + + signingClient = await getSigningHyperwebClient({ + rpcEndpoint: await getRpcEndpoint(), + signer: wallet + }); + + fee = { amount: [{ denom, amount: '100000' }], gas: '550000' }; + + await creditFromFaucet(address); + await sleep(10000); + }); + + it('Check initial balance', async () => { + const balance = await signingClient.getBalance(address, denom); + expect(balance.amount).toEqual("10000000000"); + expect(balance.denom).toEqual(denom); + }); + + it('Instantiate Token Factory contract', async () => { + const contractPath = path.join( + __dirname, + "../dist/contracts/token-factory.js" + ); + contractCode = fs.readFileSync(contractPath, "utf8"); + + const msg = hyperweb.hvm.MessageComposer.fromPartial.instantiate({ + creator: address, + code: contractCode, + source: "test_source", + }); + + const result = await signingClient.signAndBroadcast(address, [msg], fee); + assertIsDeliverTxSuccess(result); + + const response = hyperweb.hvm.MsgInstantiateResponse.fromProtoMsg(result.msgResponses[0]); + contractIndex = response.index; + contractAddress = response.address; + expect(contractIndex).toBeGreaterThan(0); + console.log(`contract instantiated at index: ${contractIndex} and address ${contractAddress}`); + }); + + it('Create new denom', async () => { + const args = JSON.stringify({ denom: "testdenom" }); + const msg = hyperweb.hvm.MessageComposer.fromPartial.eval({ + address: contractAddress, + creator: address, + callee: "createDenom", + args: [args] + }); + + const result = await signingClient.signAndBroadcast(address, [msg], fee); + assertIsDeliverTxSuccess(result); + + const response = hyperweb.hvm.MsgEvalResponse.fromProtoMsg(result.msgResponses[0]); + fullDenom = response.result; + console.log("created fullDenom:", fullDenom); + expect(fullDenom).toContain("factory"); + }); + + it('Mint tokens using fullDenom', async () => { + const args = JSON.stringify({ denom: fullDenom, amount: 1000 }); + const msg = hyperweb.hvm.MessageComposer.fromPartial.eval({ + address: contractAddress, + creator: address, + callee: "mintTokens", + args: [args] + }); + + const result = await signingClient.signAndBroadcast(address, [msg], fee); + assertIsDeliverTxSuccess(result); + }); + + it('Check balance of minted tokens', async () => { + const args = JSON.stringify({ address, denom: fullDenom }); + const msg = hyperweb.hvm.MessageComposer.fromPartial.eval({ + address: contractAddress, + creator: address, + callee: "getBalance", + args: [args] + }); + + const result = await signingClient.signAndBroadcast(address, [msg], fee); + assertIsDeliverTxSuccess(result); + + const response = hyperweb.hvm.MsgEvalResponse.fromProtoMsg(result.msgResponses[0]); + expect(parseInt(response.result)).toBeGreaterThanOrEqual(1000); + }); + + +}); From 1d0f30ac3c8d7343b806e08aa315e8e0d58a9dbc Mon Sep 17 00:00:00 2001 From: jovonni Date: Mon, 24 Mar 2025 16:14:51 -0400 Subject: [PATCH 13/13] chore(dist): added contract artifacts --- templates/hyperweb/dist/contracts/bank.js | 19 ++++++++++ templates/hyperweb/dist/contracts/bank.js.map | 7 ++++ templates/hyperweb/dist/contracts/hello.js | 14 ++++++++ .../hyperweb/dist/contracts/hello.js.map | 7 ++++ .../hyperweb/dist/contracts/simple-state.js | 33 +++++++++++++++++ .../dist/contracts/simple-state.js.map | 7 ++++ .../hyperweb/dist/contracts/token-factory.js | 36 +++++++++++++++++++ .../dist/contracts/token-factory.js.map | 7 ++++ 8 files changed, 130 insertions(+) create mode 100644 templates/hyperweb/dist/contracts/bank.js create mode 100644 templates/hyperweb/dist/contracts/bank.js.map create mode 100644 templates/hyperweb/dist/contracts/hello.js create mode 100644 templates/hyperweb/dist/contracts/hello.js.map create mode 100644 templates/hyperweb/dist/contracts/simple-state.js create mode 100644 templates/hyperweb/dist/contracts/simple-state.js.map create mode 100644 templates/hyperweb/dist/contracts/token-factory.js create mode 100644 templates/hyperweb/dist/contracts/token-factory.js.map diff --git a/templates/hyperweb/dist/contracts/bank.js b/templates/hyperweb/dist/contracts/bank.js new file mode 100644 index 00000000..3aec5692 --- /dev/null +++ b/templates/hyperweb/dist/contracts/bank.js @@ -0,0 +1,19 @@ +// src/bank/index.ts +import { getBalance, sendCoins } from "@hyperweb/bank"; +var Contract = class { + constructor() { + } + balance({ address, denom }) { + console.log("checking balance for address:", address, "denom:", denom); + return getBalance(address, denom).amount.toString(); + } + transfer({ from, to, amount, denom }) { + console.log("transferring", amount, "of", denom, "from", from, "to", to); + sendCoins(from, to, `${amount}${denom}`); + return "Transfer successful"; + } +}; +export { + Contract as default +}; +//# sourceMappingURL=bank.js.map diff --git a/templates/hyperweb/dist/contracts/bank.js.map b/templates/hyperweb/dist/contracts/bank.js.map new file mode 100644 index 00000000..c371191c --- /dev/null +++ b/templates/hyperweb/dist/contracts/bank.js.map @@ -0,0 +1,7 @@ +{ + "version": 3, + "sources": ["../../src/bank/index.ts"], + "sourcesContent": ["// @ts-ignore\nimport { getBalance, sendCoins } from \"@hyperweb/bank\";\n\nexport default class Contract {\n constructor() { }\n\n balance({ address, denom }: { address: string; denom: string }): string {\n console.log(\"checking balance for address:\", address, \"denom:\", denom);\n return getBalance(address, denom).amount.toString();\n }\n\n transfer({ from, to, amount, denom }: {\n from: string;\n to: string;\n amount: number;\n denom: string\n }): string {\n console.log(\"transferring\", amount, \"of\", denom, \"from\", from, \"to\", to);\n sendCoins(from, to, `${amount}${denom}`);\n return \"Transfer successful\";\n }\n}"], + "mappings": ";AACA,SAAS,YAAY,iBAAiB;AAEtC,IAAqB,WAArB,MAA8B;AAAA,EAC1B,cAAc;AAAA,EAAE;AAAA,EAEhB,QAAQ,EAAE,SAAS,MAAM,GAA+C;AACpE,YAAQ,IAAI,iCAAiC,SAAS,UAAU,KAAK;AACrE,WAAO,WAAW,SAAS,KAAK,EAAE,OAAO,SAAS;AAAA,EACtD;AAAA,EAEA,SAAS,EAAE,MAAM,IAAI,QAAQ,MAAM,GAKxB;AACP,YAAQ,IAAI,gBAAgB,QAAQ,MAAM,OAAO,QAAQ,MAAM,MAAM,EAAE;AACvE,cAAU,MAAM,IAAI,GAAG,MAAM,GAAG,KAAK,EAAE;AACvC,WAAO;AAAA,EACX;AACJ;", + "names": [] +} diff --git a/templates/hyperweb/dist/contracts/hello.js b/templates/hyperweb/dist/contracts/hello.js new file mode 100644 index 00000000..8b2fe2fb --- /dev/null +++ b/templates/hyperweb/dist/contracts/hello.js @@ -0,0 +1,14 @@ +// src/hello/index.ts +var Contract = class { + state; + constructor() { + } + hello(x) { + this.state.msg = x; + return `Hello, ${String(this.state.msg)}`; + } +}; +export { + Contract as default +}; +//# sourceMappingURL=hello.js.map diff --git a/templates/hyperweb/dist/contracts/hello.js.map b/templates/hyperweb/dist/contracts/hello.js.map new file mode 100644 index 00000000..424f8212 --- /dev/null +++ b/templates/hyperweb/dist/contracts/hello.js.map @@ -0,0 +1,7 @@ +{ + "version": 3, + "sources": ["../../src/hello/index.ts"], + "sourcesContent": ["export default class Contract {\n state: {\n msg?: string | boolean | null;\n };\n\n constructor() { }\n\n hello(x: string) {\n this.state.msg = x;\n return `Hello, ${String(this.state.msg)}`;\n }\n}\n"], + "mappings": ";AAAA,IAAqB,WAArB,MAA8B;AAAA,EAC1B;AAAA,EAIA,cAAc;AAAA,EAAE;AAAA,EAEhB,MAAM,GAAW;AACb,SAAK,MAAM,MAAM;AACjB,WAAO,UAAU,OAAO,KAAK,MAAM,GAAG,CAAC;AAAA,EAC3C;AACJ;", + "names": [] +} diff --git a/templates/hyperweb/dist/contracts/simple-state.js b/templates/hyperweb/dist/contracts/simple-state.js new file mode 100644 index 00000000..a2c93337 --- /dev/null +++ b/templates/hyperweb/dist/contracts/simple-state.js @@ -0,0 +1,33 @@ +// src/simple-state/index.ts +var Contract = class { + state; + constructor() { + console.log("[Contract] constructor called"); + } + reset() { + console.log("[Contract] reset called"); + this.state.value = 0; + } + init() { + console.log("[Contract] init called"); + this.state.value = 0; + return this.state.value; + } + inc(x) { + console.log("[Contract] inc called"); + this.state.value += x; + return this.state.value; + } + dec(x) { + console.log("[Contract] dec called"); + this.state.value -= x; + } + read() { + console.log("[Contract] read called"); + return this.state.value; + } +}; +export { + Contract as default +}; +//# sourceMappingURL=simple-state.js.map diff --git a/templates/hyperweb/dist/contracts/simple-state.js.map b/templates/hyperweb/dist/contracts/simple-state.js.map new file mode 100644 index 00000000..99d5867a --- /dev/null +++ b/templates/hyperweb/dist/contracts/simple-state.js.map @@ -0,0 +1,7 @@ +{ + "version": 3, + "sources": ["../../src/simple-state/index.ts"], + "sourcesContent": ["export interface State {\n value: number;\n}\n\nexport default class Contract {\n state: State;\n\n constructor() {\n console.log(\"[Contract] constructor called\");\n }\n\n reset() {\n console.log(\"[Contract] reset called\");\n this.state.value = 0;\n }\n\n init(): number {\n console.log(\"[Contract] init called\");\n this.state.value = 0;\n return this.state.value\n }\n\n inc(x: number): number {\n console.log(\"[Contract] inc called\");\n this.state.value += x;\n return this.state.value;\n }\n\n dec(x: number) {\n console.log(\"[Contract] dec called\");\n this.state.value -= x;\n }\n\n read() {\n console.log(\"[Contract] read called\");\n return this.state.value;\n }\n}\n"], + "mappings": ";AAIA,IAAqB,WAArB,MAA8B;AAAA,EAC5B;AAAA,EAEA,cAAc;AACZ,YAAQ,IAAI,+BAA+B;AAAA,EAC7C;AAAA,EAEA,QAAQ;AACN,YAAQ,IAAI,yBAAyB;AACrC,SAAK,MAAM,QAAQ;AAAA,EACrB;AAAA,EAEA,OAAe;AACb,YAAQ,IAAI,wBAAwB;AACpC,SAAK,MAAM,QAAQ;AACnB,WAAO,KAAK,MAAM;AAAA,EACpB;AAAA,EAEA,IAAI,GAAmB;AACrB,YAAQ,IAAI,uBAAuB;AACnC,SAAK,MAAM,SAAS;AACpB,WAAO,KAAK,MAAM;AAAA,EACpB;AAAA,EAEA,IAAI,GAAW;AACb,YAAQ,IAAI,uBAAuB;AACnC,SAAK,MAAM,SAAS;AAAA,EACtB;AAAA,EAEA,OAAO;AACL,YAAQ,IAAI,wBAAwB;AACpC,WAAO,KAAK,MAAM;AAAA,EACpB;AACF;", + "names": [] +} diff --git a/templates/hyperweb/dist/contracts/token-factory.js b/templates/hyperweb/dist/contracts/token-factory.js new file mode 100644 index 00000000..968cf3ca --- /dev/null +++ b/templates/hyperweb/dist/contracts/token-factory.js @@ -0,0 +1,36 @@ +// src/token-factory/index.ts +import { createDenom, mintTokens, burnTokens } from "@hyperweb/token"; +import { getBalance } from "@hyperweb/bank"; +var Contract = class { + msg; + constructor() { + } + createDenom({ denom }) { + console.log("denom:", denom); + const token = createDenom(this.msg.sender, denom); + console.log("created token:", token); + return token; + } + mintTokens({ denom, amount }) { + console.log("minting tokens:", amount, "of", denom); + const minted = mintTokens(this.msg.sender, denom, amount); + console.log("minted:", minted); + return minted; + } + burnTokens({ denom, amount }) { + console.log("burning tokens:", amount, "of", denom); + const burned = burnTokens(this.msg.sender, denom, amount); + console.log("burned:", burned); + return burned; + } + getBalance({ address, denom }) { + console.log("checking balance for address:", address, "denom:", denom); + const balance = getBalance(address, denom); + console.log("balance:", balance.amount); + return balance.amount; + } +}; +export { + Contract as default +}; +//# sourceMappingURL=token-factory.js.map diff --git a/templates/hyperweb/dist/contracts/token-factory.js.map b/templates/hyperweb/dist/contracts/token-factory.js.map new file mode 100644 index 00000000..48e857f5 --- /dev/null +++ b/templates/hyperweb/dist/contracts/token-factory.js.map @@ -0,0 +1,7 @@ +{ + "version": 3, + "sources": ["../../src/token-factory/index.ts"], + "sourcesContent": ["// @ts-ignore\nimport { createDenom, mintTokens, burnTokens } from '@hyperweb/token';\n// @ts-ignore\nimport { getBalance } from '@hyperweb/bank';\n\nexport default class Contract {\n private msg: { sender: string };\n constructor() { }\n\n createDenom({ denom }: { denom: string }) {\n console.log(\"denom:\", denom);\n const token = createDenom(this.msg.sender, denom);\n console.log(\"created token:\", token);\n return token;\n }\n\n mintTokens({ denom, amount }: { denom: string; amount: number }) {\n console.log(\"minting tokens:\", amount, \"of\", denom);\n const minted = mintTokens(this.msg.sender, denom, amount);\n console.log(\"minted:\", minted);\n return minted;\n }\n\n burnTokens({ denom, amount }: { denom: string; amount: number }) {\n console.log(\"burning tokens:\", amount, \"of\", denom);\n const burned = burnTokens(this.msg.sender, denom, amount);\n console.log(\"burned:\", burned);\n return burned;\n }\n\n getBalance({ address, denom }: { address: string; denom: string }) {\n console.log(\"checking balance for address:\", address, \"denom:\", denom);\n const balance = getBalance(address, denom);\n console.log(\"balance:\", balance.amount);\n return balance.amount;\n }\n}\n"], + "mappings": ";AACA,SAAS,aAAa,YAAY,kBAAkB;AAEpD,SAAS,kBAAkB;AAE3B,IAAqB,WAArB,MAA8B;AAAA,EAClB;AAAA,EACR,cAAc;AAAA,EAAE;AAAA,EAEhB,YAAY,EAAE,MAAM,GAAsB;AACtC,YAAQ,IAAI,UAAU,KAAK;AAC3B,UAAM,QAAQ,YAAY,KAAK,IAAI,QAAQ,KAAK;AAChD,YAAQ,IAAI,kBAAkB,KAAK;AACnC,WAAO;AAAA,EACX;AAAA,EAEA,WAAW,EAAE,OAAO,OAAO,GAAsC;AAC7D,YAAQ,IAAI,mBAAmB,QAAQ,MAAM,KAAK;AAClD,UAAM,SAAS,WAAW,KAAK,IAAI,QAAQ,OAAO,MAAM;AACxD,YAAQ,IAAI,WAAW,MAAM;AAC7B,WAAO;AAAA,EACX;AAAA,EAEA,WAAW,EAAE,OAAO,OAAO,GAAsC;AAC7D,YAAQ,IAAI,mBAAmB,QAAQ,MAAM,KAAK;AAClD,UAAM,SAAS,WAAW,KAAK,IAAI,QAAQ,OAAO,MAAM;AACxD,YAAQ,IAAI,WAAW,MAAM;AAC7B,WAAO;AAAA,EACX;AAAA,EAEA,WAAW,EAAE,SAAS,MAAM,GAAuC;AAC/D,YAAQ,IAAI,iCAAiC,SAAS,UAAU,KAAK;AACrE,UAAM,UAAU,WAAW,SAAS,KAAK;AACzC,YAAQ,IAAI,YAAY,QAAQ,MAAM;AACtC,WAAO,QAAQ;AAAA,EACnB;AACJ;", + "names": [] +}