UNPKG

@apillon/sdk

Version:

▶◀ Apillon SDK for NodeJS ▶◀

131 lines 6.11 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); const docs_index_1 = require("../docs-index"); const computing_1 = require("../modules/computing/computing"); const computing_contract_1 = require("../modules/computing/computing-contract"); const computing_2 = require("../types/computing"); const helper_1 = require("./helpers/helper"); const path_1 = require("path"); const fs = __importStar(require("fs")); describe('Computing tests', () => { let computing; let contractUuid; let receivingAddress; let bucket_uuid; const name = 'Schrodinger SDK Test'; const description = 'Schrodinger SDK Test computing contract'; const nftContractAddress = '0xe6C61ef02729a190Bd940A3077f8464c27C2E593'; beforeAll(() => { computing = new computing_1.Computing((0, helper_1.getConfig)()); contractUuid = (0, helper_1.getComputingContractUUID)(); receivingAddress = (0, helper_1.getPhalaAddress)(); bucket_uuid = (0, helper_1.getBucketUUID)(); }); test('Create new contract', async () => { const contract = await computing.createContract({ name, description, bucket_uuid, contractData: { nftContractAddress, nftChainRpcUrl: docs_index_1.ChainRpcUrl.MOONBASE, }, }); expect(contract).toBeInstanceOf(computing_contract_1.ComputingContract); expect(contract.name).toEqual(name); expect(contract.description).toEqual(description); expect(contract.uuid).toBeTruthy(); expect(contract.bucketUuid).toEqual(bucket_uuid); expect(contract.data.nftContractAddress).toEqual(nftContractAddress); expect(contract.data.nftChainRpcUrl).toEqual(docs_index_1.ChainRpcUrl.MOONBASE); contractUuid = contract.uuid; }); test('Creating new contract with missing contract data should fail', async () => { const createContract = () => computing.createContract({ name, description, bucket_uuid, contractData: { nftContractAddress: undefined, nftChainRpcUrl: undefined, }, }); await expect(createContract).rejects.toThrow(); }); test('List contracts', async () => { const { items } = await computing.listContracts(); expect(items.length).toBeGreaterThanOrEqual(0); items.forEach((contract) => { expect(contract instanceof computing_contract_1.ComputingContract).toBeTruthy(); expect(contract.name).toBeTruthy(); }); expect(items.find((contract) => contract.uuid === contractUuid)).toBeTruthy(); }); test('Get specific contract', async () => { const contract = await computing.contract(contractUuid).get(); expect(contract).toBeInstanceOf(computing_contract_1.ComputingContract); expect(contract.name).toEqual(name); expect(contract.description).toEqual(description); expect(contract.uuid).toEqual(contractUuid); expect(contract.data.nftContractAddress).toEqual(nftContractAddress); expect(contract.data.nftChainRpcUrl).toEqual(docs_index_1.ChainRpcUrl.MOONBASE); }); test('List all transactions for computing contract', async () => { const { items } = await computing .contract(contractUuid) .listTransactions({ limit: 10 }); expect(items.length).toBeGreaterThanOrEqual(0); items.forEach((transaction) => { expect(transaction).toBeDefined(); expect(transaction.transactionHash).toBeDefined(); expect(Object.keys(computing_2.ComputingContractStatus).includes(transaction.transactionStatus.toString())); expect(Object.keys(computing_2.ComputingTransactionType).includes(transaction.transactionType.toString())); }); }); test('List all transactions with specific type', async () => { const { items } = await computing.contract(contractUuid).listTransactions({ transactionType: computing_2.ComputingTransactionType.DEPLOY_CONTRACT, }); expect(items.length).toEqual(1); expect(items[0].transactionType).toEqual(computing_2.ComputingTransactionType.DEPLOY_CONTRACT); }); test.skip('Encrypt data using computing contract', async () => { const html = fs.readFileSync((0, path_1.resolve)(__dirname, './helpers/website/style.css')); const files = await computing .contract(contractUuid) .encryptFile({ content: html, fileName: 'style.css', nftId: 5 }); expect(files).toHaveLength(1); expect(files[0].fileName).toBe('style.css'); expect(files[0].CID).toBeDefined(); }); test.skip('Transfer ownership of computing contract', async () => { const success = await computing .contract(contractUuid) .transferOwnership(receivingAddress); expect(success).toBeTruthy(); }); }); //# sourceMappingURL=computing.test.js.map