diff --git a/src/blockchain/Blockchain.spec.ts b/src/blockchain/Blockchain.spec.ts index e37080a..29b88c1 100644 --- a/src/blockchain/Blockchain.spec.ts +++ b/src/blockchain/Blockchain.spec.ts @@ -214,6 +214,39 @@ describe('Blockchain', () => { op: 0xfffffffe, body: (x: Cell) => x.beginParse().skip(32).loadUint(32) === 3, }) + + // Current time in receiveMessage should match blockchain.now + const nowSmc = await blockchain.getContract(contract.address) + + let smcRes = nowSmc.receiveMessage(internal({ + from: sender.address, + to: nowSmc.address, + body: beginCell().storeUint(0, 32).storeAddress(sender.address).endCell(), + value: toNano('1') + })) + + expect(smcRes.now).toBe(3) + expect(smcRes.outMessagesCount).toBe(1) + + let respMsg = smcRes.outMessages.get(0)! + if (respMsg.info.type !== 'internal') throw new Error('Internal message expected') + expect(respMsg.body.beginParse().skip(32).preloadUint(32)).toEqual(3) + + // Make sure now is still overridable in receiveMessage call + + smcRes = nowSmc.receiveMessage(internal({ + from: sender.address, + to: nowSmc.address, + body: beginCell().storeUint(0, 32).storeAddress(sender.address).endCell(), + value: toNano('1') + }), {now: 4}) + + expect(smcRes.now).toBe(4) + expect(smcRes.outMessagesCount).toBe(1) + + respMsg = smcRes.outMessages.get(0)! + if (respMsg.info.type !== 'internal') throw new Error('Internal message expected') + expect(respMsg.body.beginParse().skip(32).preloadUint(32)).toEqual(4) }) it('execution result in step by step mode should match one in regular mode', async() => { diff --git a/src/blockchain/SmartContract.ts b/src/blockchain/SmartContract.ts index 2490fae..c9c337c 100644 --- a/src/blockchain/SmartContract.ts +++ b/src/blockchain/SmartContract.ts @@ -248,6 +248,11 @@ export class SmartContract { } receiveMessage(message: Message, params?: MessageParams) { + // Sync now with blockchain instance if not specified in parameters + params = { + now: this.blockchain.now, + ...params, + } return this.runCommon(() => this.blockchain.executor.runTransaction({ ...this.createCommonArgs(params), message: beginCell().store(storeMessage(message)).endCell(),