UNPKG

@ton/ton

Version:

[![Version npm](https://img.shields.io/npm/v/ton.svg?logo=npm)](https://www.npmjs.com/package/ton)

75 lines (74 loc) 3.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@ton/core"); const WalletContractV4Actions_1 = require("./WalletContractV4Actions"); describe('Wallet V5R1 actions', () => { it('should serialize and deserialize OutActionSendMsg', async () => { const msg = { type: 'sendMsg', messages: [(0, core_1.internal)({ to: new core_1.Address(0, Buffer.alloc(32, 0xaa)), value: '0.001', })], sendMode: core_1.SendMode.PAY_GAS_SEPARATELY, }; const serialized = (0, core_1.beginCell)().store((0, WalletContractV4Actions_1.storeExtendedAction)(msg)).endCell(); const deserialized = (0, WalletContractV4Actions_1.loadExtendedAction)(serialized.beginParse()); if (deserialized.type !== 'sendMsg') throw new Error(); expect(deserialized.messages.length).toEqual(msg.messages.length); expect(deserialized.messages[0].info.dest.toString()).toEqual(msg.messages[0].info.dest.toString()); expect(deserialized.sendMode).toEqual(msg.sendMode); }); it('should serialize and deserialize OutActionAddAndDeployPlugin', () => { const stateInit = { code: (0, core_1.beginCell)().storeUint(0xa, 4).endCell(), data: (0, core_1.beginCell)().storeUint(0xb, 4).endCell(), }; const action = { type: 'addAndDeployPlugin', workchain: -1, stateInit, body: (0, core_1.beginCell)().storeUint(0xcc, 8).endCell(), forwardAmount: 1000n, }; const serialized = (0, core_1.beginCell)().store((0, WalletContractV4Actions_1.storeExtendedAction)(action)).endCell(); const deserialized = (0, WalletContractV4Actions_1.loadExtendedAction)(serialized.beginParse()); if (deserialized.type !== 'addAndDeployPlugin') throw new Error(); expect(deserialized.workchain).toEqual(action.workchain); expect(deserialized.forwardAmount).toEqual(action.forwardAmount); expect(deserialized.body.equals(action.body)).toBe(true); expect(deserialized.stateInit.code?.equals(action.stateInit.code)).toBe(true); expect(deserialized.stateInit.data?.equals(action.stateInit.data)).toBe(true); }); it('should serialize and deserialize OutActionAddPlugin', () => { const action = { type: 'addPlugin', address: new core_1.Address(0, Buffer.alloc(32, 0xaa)), forwardAmount: 123n, queryId: 77n, }; const serialized = (0, core_1.beginCell)().store((0, WalletContractV4Actions_1.storeExtendedAction)(action)).endCell(); const deserialized = (0, WalletContractV4Actions_1.loadExtendedAction)(serialized.beginParse()); if (deserialized.type !== 'addPlugin') throw new Error(); expect(deserialized.address.equals(action.address)).toBe(true); expect(deserialized.forwardAmount).toEqual(action.forwardAmount); expect(deserialized.queryId).toEqual(action.queryId); }); it('should serialize and deserialize OutActionRemovePlugin', () => { const action = { type: 'removePlugin', address: new core_1.Address(0, Buffer.alloc(32, 0xbb)), forwardAmount: 987654321n, }; const serialized = (0, core_1.beginCell)().store((0, WalletContractV4Actions_1.storeExtendedAction)(action)).endCell(); const deserialized = (0, WalletContractV4Actions_1.loadExtendedAction)(serialized.beginParse()); if (deserialized.type !== 'removePlugin') throw new Error(); expect(deserialized.address.equals(action.address)).toBe(true); expect(deserialized.forwardAmount).toEqual(action.forwardAmount); expect(deserialized.queryId).toBeUndefined(); }); });