Skip to content

Commit

Permalink
fix: now in SmartContract.reveiveMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinketer22 authored Oct 3, 2023
1 parent e06eb6b commit dc67632
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/blockchain/Blockchain.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() => {
Expand Down
5 changes: 5 additions & 0 deletions src/blockchain/SmartContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit dc67632

Please sign in to comment.