UNPKG

stellar-plus

Version:

beta version of stellar-plus, an all-in-one sdk for the Stellar blockchain

86 lines (85 loc) 4.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const contract_1 = require("@stellar/stellar-sdk/contract"); const account_1 = require("../../../stellar-plus/account"); const contract_engine_1 = require("../../../stellar-plus/core/contract-engine"); const network_1 = require("../../../stellar-plus/network"); const stellar_test_ledger_1 = require("../../../stellar-plus/test/stellar-test-ledger"); const regex_1 = require("../../../stellar-plus/utils/regex"); const spec_1 = require("../../../tests/contracts/hello-world/spec"); const utils_1 = require("../../../tests/utils"); describe('Hello World Contract Use Case: ', () => { const logLevel = 'TRACE'; const stellarTestLedger = new stellar_test_ledger_1.StellarTestLedger({ logLevel, network: stellar_test_ledger_1.TestLedgerNetwork.LOCAL, containerImageVersion: stellar_test_ledger_1.SupportedImageVersions.LASTEST, }); let helloWorldSpec; let networkConfig; let wasmBuffer; beforeAll(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () { // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const container = yield stellarTestLedger.start(); expect(container).toBeDefined(); networkConfig = (0, network_1.CustomNet)(yield stellarTestLedger.getNetworkConfiguration()); expect(networkConfig.horizonUrl).toBeDefined(); expect(networkConfig.networkPassphrase).toBeDefined(); expect(networkConfig.rpcUrl).toBeDefined(); expect(networkConfig.friendbotUrl).toBeDefined(); wasmBuffer = yield (0, utils_1.loadWasmFile)('./src/tests/contracts/hello-world/hello_world.wasm'); expect(wasmBuffer).toBeDefined(); helloWorldSpec = new contract_1.Spec(spec_1.spec); })); afterAll(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () { yield stellarTestLedger.stop(); yield stellarTestLedger.destroy(); })); describe('Given an admin with lumens', () => { let admin; let adminTxInvocation; beforeAll(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () { admin = new account_1.DefaultAccountHandler({ networkConfig }); yield admin.initializeWithFriendbot(); expect(admin).toBeDefined(); adminTxInvocation = { header: { source: admin.getPublicKey(), fee: '100000', timeout: 0, }, signers: [admin], }; })); describe('A Contract Engine', () => { let helloWorld; beforeAll(() => { helloWorld = new contract_engine_1.ContractEngine({ contractParameters: { wasm: wasmBuffer, spec: helloWorldSpec, }, networkConfig, }); expect(helloWorld).toBeDefined(); }); it('should upload the wasm buffer and update the wasm hash', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { yield expect(helloWorld.uploadWasm(adminTxInvocation)).toResolve(); expect(helloWorld.getWasmHash()).toBeDefined(); expect(helloWorld.getWasmHash()).toMatch(regex_1.wasmHashRegex); })); it('should deploy the contract using the wasm hash and update the contract id', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { yield expect(helloWorld.deploy(adminTxInvocation)).toResolve(); expect(helloWorld.getContractId()).toBeDefined(); expect(helloWorld.getContractId()).toMatch(regex_1.contractIdRegex); })); it('should invoke the contract method GetName that returns an output', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { yield expect(helloWorld.invokeContract(Object.assign({ method: spec_1.methods.getName, methodArgs: {} }, adminTxInvocation))).resolves.toBe('CaptainCacti'); })); it('should read from the contract state by just simulating the GetName execution and return and output', () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { yield expect(helloWorld.readFromContract(Object.assign({ method: spec_1.methods.getName, methodArgs: {} }, adminTxInvocation))).resolves.toBe('CaptainCacti'); })); }); }); });