Skip to content

Commit

Permalink
Fix counter from tx.
Browse files Browse the repository at this point in the history
  • Loading branch information
msinkec committed Feb 14, 2024
1 parent fe577b0 commit a567773
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion tests/counter2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Counter2 } from '../src/contracts/counter2'
import { getDefaultSigner } from './utils/helper'
import { MethodCallOptions } from 'scrypt-ts'

describe('Test SmartContract `Counter 2`', () => {
describe('Test SmartContract `Counter2`', () => {
before(() => {
Counter2.loadArtifact()
})
Expand Down
15 changes: 6 additions & 9 deletions tests/counterFromTx.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { use } from 'chai'
import { Counter } from '../src/contracts/counter'
import { getDefaultSigner } from './utils/helper'
import { MethodCallOptions,} from 'scrypt-ts'
import { MethodCallOptions } from 'scrypt-ts'
import chaiAsPromised from 'chai-as-promised'
use(chaiAsPromised)
describe('Test SmartContract `Counter`', () => {
describe('Test SmartContract `Counter` from tx', () => {
before(() => {
Counter.loadArtifact()
})
Expand All @@ -19,13 +19,11 @@ describe('Test SmartContract `Counter`', () => {
await counter.connect(signer)
const deployTx = await counter.deploy(1)

// set current instance to be the deployed one
let instance = counter
let callTx = deployTx

// call the method of current instance to apply the updates on chain
for (let i = 0; i < 5; ++i) {

instance = Counter.fromTx(deployTx, atOutputIndex)
const instance = Counter.fromTx(callTx, atOutputIndex)

await instance.connect(signer)

Expand All @@ -35,7 +33,7 @@ describe('Test SmartContract `Counter`', () => {
// apply updates on the next instance off chain
nextInstance.increment()

const { tx: callTx } = await instance.methods.incrementOnChain({
const callRes = await instance.methods.incrementOnChain({
next: {
instance: nextInstance,
balance: instance.balance,
Expand All @@ -45,8 +43,7 @@ describe('Test SmartContract `Counter`', () => {
`Counter incrementOnChain called: ${callTx.id}, the count now is: ${nextInstance.count}`
)

// update the current instance reference
instance = nextInstance
callTx = callRes.tx
}
})
})

0 comments on commit a567773

Please sign in to comment.