Skip to content

Commit

Permalink
Merge pull request #321 from yusufidimaina9989/master
Browse files Browse the repository at this point in the history
update counterFromTx.test.ts
  • Loading branch information
yusufidimaina9989 authored Feb 11, 2024
2 parents 00be3e6 + e26086d commit fe577b0
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tests/counterFromTx.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { use } from 'chai'
import { Counter } from '../src/contracts/counter'
import { getDefaultSigner } from './utils/helper'
import { MethodCallOptions,} from 'scrypt-ts'
import chaiAsPromised from 'chai-as-promised'
use(chaiAsPromised)
describe('Test SmartContract `Counter`', () => {
before(() => {
Counter.loadArtifact()
})

it('should pass the public method unit test successfully.', async () => {
const balance = 1

const initialCount: bigint = 100n
const atOutputIndex = 0
const counter = new Counter(initialCount)
const signer = getDefaultSigner()
await counter.connect(signer)
const deployTx = await counter.deploy(1)

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

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

instance = Counter.fromTx(deployTx, atOutputIndex)

await instance.connect(signer)

// create the next instance from the current
const nextInstance = instance.next()

// apply updates on the next instance off chain
nextInstance.increment()

const { tx: callTx } = await instance.methods.incrementOnChain({
next: {
instance: nextInstance,
balance: instance.balance,
},
} as MethodCallOptions<Counter>)
console.log(
`Counter incrementOnChain called: ${callTx.id}, the count now is: ${nextInstance.count}`
)

// update the current instance reference
instance = nextInstance
}
})
})

0 comments on commit fe577b0

Please sign in to comment.