From 4341ea1422cd2391f2ac55e6838aeecdef1df403 Mon Sep 17 00:00:00 2001 From: Bun Date: Fri, 9 Sep 2022 21:55:08 -0400 Subject: [PATCH] New cosmwasm-vm-js version --- jest.config.js | 9 ++++++--- package-lock.json | 34 +++++++++++++++++++++++----------- package.json | 2 +- src/contract.ts | 8 +++----- src/engine.spec.ts | 45 ++++++++++++++++++++++++++++++++++++++++----- 5 files changed, 73 insertions(+), 25 deletions(-) diff --git a/jest.config.js b/jest.config.js index a78a4ff..f9ec744 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,5 +1,8 @@ module.exports = { - testEnvironment: 'node', - preset: 'ts-jest', - roots: ['/src'], + preset: 'ts-jest', + testEnvironment: 'node', + transform: { + '^.+\\.ts?$': 'ts-jest', + }, + transformIgnorePatterns: ['/node_modules/'], }; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 1d7bc29..f863a2a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,18 +1,18 @@ { - "name": "cw-simulate", - "version": "1.0.0", + "name": "@terran-one/cw-simulate", + "version": "1.0.3", "lockfileVersion": 2, "requires": true, "packages": { "": { - "name": "cw-simulate", - "version": "1.0.0", + "name": "@terran-one/cw-simulate", + "version": "1.0.3", "license": "MIT", "dependencies": { "@cosmjs/amino": "^0.28.13", "@cosmjs/crypto": "^0.28.13", "@cosmjs/encoding": "^0.28.13", - "@terran-one/cosmwasm-vm-js": "^0.1.11", + "@terran-one/cosmwasm-vm-js": "^0.1.12", "@types/lodash": "^4.14.184", "lobyte": "^0.0.3", "lodash": "^4.17.21" @@ -1557,9 +1557,9 @@ } }, "node_modules/@terran-one/cosmwasm-vm-js": { - "version": "0.1.11", - "resolved": "https://npm.pkg.github.com/download/@Terran-One/cosmwasm-vm-js/0.1.11/c57feeed3331e87539df162bb643f94881593327", - "integrity": "sha512-40fov8bq3tlbb89LVWfhI1uNq2qaWYT02v39LSRho2x8DkjJ8b7SGOShcuJmncAS8dh8kX9GwJxKEVNdBfYIWg==", + "version": "0.1.12", + "resolved": "https://npm.pkg.github.com/download/@Terran-One/cosmwasm-vm-js/0.1.12/d16b61addb8d750a10df2979642107a0ea764b4a", + "integrity": "sha512-HvwKUtja+csZDbnqyJDivCXEKtMh3OIvIgFIKNpLXfWxSkLsV6WzxVwdqXqgQH9A2OCbhvHi/ktr8ifBYe61Tw==", "license": "MIT", "dependencies": { "@cosmjs/crypto": "^0.28.4", @@ -1568,6 +1568,7 @@ "@types/secp256k1": "^4.0.3", "bech32": "^2.0.0", "elliptic": "^6.5.4", + "immutable": "^4.1.0", "process": "^0.11.10", "secp256k1": "^4.0.3", "synchronized-promise": "^0.3.1", @@ -3498,6 +3499,11 @@ } ] }, + "node_modules/immutable": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/immutable/-/immutable-4.1.0.tgz", + "integrity": "sha512-oNkuqVTA8jqG1Q6c+UglTOD1xhC1BtjKI7XkCXRkZHrN5m18/XsnUp8Q89GkQO/z+0WjonSvl0FLhDYftp46nQ==" + }, "node_modules/import-local": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/import-local/-/import-local-3.1.0.tgz", @@ -8434,9 +8440,9 @@ } }, "@terran-one/cosmwasm-vm-js": { - "version": "0.1.11", - "resolved": "https://npm.pkg.github.com/download/@Terran-One/cosmwasm-vm-js/0.1.11/c57feeed3331e87539df162bb643f94881593327", - "integrity": "sha512-40fov8bq3tlbb89LVWfhI1uNq2qaWYT02v39LSRho2x8DkjJ8b7SGOShcuJmncAS8dh8kX9GwJxKEVNdBfYIWg==", + "version": "0.1.12", + "resolved": "https://npm.pkg.github.com/download/@Terran-One/cosmwasm-vm-js/0.1.12/d16b61addb8d750a10df2979642107a0ea764b4a", + "integrity": "sha512-HvwKUtja+csZDbnqyJDivCXEKtMh3OIvIgFIKNpLXfWxSkLsV6WzxVwdqXqgQH9A2OCbhvHi/ktr8ifBYe61Tw==", "requires": { "@cosmjs/crypto": "^0.28.4", "@cosmjs/encoding": "^0.28.4", @@ -8444,6 +8450,7 @@ "@types/secp256k1": "^4.0.3", "bech32": "^2.0.0", "elliptic": "^6.5.4", + "immutable": "^4.1.0", "process": "^0.11.10", "secp256k1": "^4.0.3", "synchronized-promise": "^0.3.1", @@ -9996,6 +10003,11 @@ "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", "dev": true }, + "immutable": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/immutable/-/immutable-4.1.0.tgz", + "integrity": "sha512-oNkuqVTA8jqG1Q6c+UglTOD1xhC1BtjKI7XkCXRkZHrN5m18/XsnUp8Q89GkQO/z+0WjonSvl0FLhDYftp46nQ==" + }, "import-local": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/import-local/-/import-local-3.1.0.tgz", diff --git a/package.json b/package.json index 183025d..0bdb994 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "@cosmjs/amino": "^0.28.13", "@cosmjs/crypto": "^0.28.13", "@cosmjs/encoding": "^0.28.13", - "@terran-one/cosmwasm-vm-js": "^0.1.11", + "@terran-one/cosmwasm-vm-js": "^0.1.12", "@types/lodash": "^4.14.184", "lobyte": "^0.0.3", "lodash": "^4.17.21" diff --git a/src/contract.ts b/src/contract.ts index c86e890..3d46f4a 100644 --- a/src/contract.ts +++ b/src/contract.ts @@ -1,16 +1,14 @@ import { - BasicKVIterStorage, - VMInstance, BasicBackendApi, + BasicKVIterStorage, BasicQuerier, IBackend, - IStorage, IIterStorage, - Region, + VMInstance, } from '@terran-one/cosmwasm-vm-js'; import { CWChain } from './chain'; -import { clone, cloneDeep } from 'lodash'; +import { cloneDeep } from 'lodash'; export class CWContractCode { constructor( diff --git a/src/engine.spec.ts b/src/engine.spec.ts index e8b567e..421ee50 100644 --- a/src/engine.spec.ts +++ b/src/engine.spec.ts @@ -1,6 +1,5 @@ import { CWSimulateEnv } from './engine'; import { readFileSync } from 'fs'; -import { fromAscii, toAscii, fromBase64, toBase64 } from '@cosmjs/encoding'; const wasmBytecode = readFileSync('testing/hello_world-aarch64.wasm'); @@ -19,10 +18,46 @@ describe('CWSimulateEnv', () => { let code = chain.storeCode(wasmBytecode); let instance = await chain.instantiateContract(code.codeId); - instance.instantiate(info, { count: 0 }); + instance.instantiate(info, {count: 0}); - let result = instance.execute(info, { increment: {} }); - instance.execute(info, { increment: {} }); - instance.execute(info, { increment: {} }); + let result = instance.execute(info, {increment: {}}); + instance.execute(info, {increment: {}}); + instance.execute(info, {increment: {}}); + }); + + it('works with multiple chains and contracts', async () => { + let env = new CWSimulateEnv(); + let chain1 = env.createChain({ + chainId: 'phoenix-1', + bech32Prefix: 'terra', + }); + + let chain2 = env.createChain({ + chainId: 'cosmoshub-2', + bech32Prefix: 'cosmos', + }); + + let info = { + sender: 'terra1hgm0p7khfk85zpz5v0j8wnej3a90w709vhkdfu', + funds: [], + }; + + expect(Object.keys(env.chains).length).toBe(2); + expect(env.chains['phoenix-1']).toEqual(JSON.parse(JSON.stringify(chain1))); + expect(env.chains['cosmoshub-2']).toEqual(JSON.parse(JSON.stringify(chain2))); + let code = chain1.storeCode(wasmBytecode); + let instance = await chain1.instantiateContract(code.codeId); + instance.instantiate(info, {count: 0}); + + let result = instance.execute(info, {increment: {}}); + + let code2 = chain2.storeCode(wasmBytecode); + let instance2 = await chain2.instantiateContract(code2.codeId); + instance2.instantiate(info, {count: 0}); + + let result2 = instance2.execute(info, {increment: {}}); + + instance.execute(info, {increment: {}}); + instance.execute(info, {increment: {}}); }); });