Skip to content

Instantly share code, notes, and snippets.

@gitzhou
Created May 17, 2023 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gitzhou/b685bdaf7c47eaa752c5c335f5c82f22 to your computer and use it in GitHub Desktop.
Save gitzhou/b685bdaf7c47eaa752c5c335f5c82f22 to your computer and use it in GitHub Desktop.
import { MethodCallOptions, PubKey, PubKeyHash, toHex } from 'scrypt-ts'
import { Pyramid } from '../../src/contracts/pyramid'
import {
getDummySigner,
getDummyUTXO,
randomPrivateKey,
} from '../utils/txHelper'
import { myPublicKeyHash, myAddress } from '../utils/privateKey'
import { expect } from 'chai'
async function main() {
await Pyramid.compile()
const pyramid = new Pyramid(PubKeyHash(toHex(myPublicKeyHash)), 1000n)
pyramid.bindTxBuilder('recruit', Pyramid.recruitTxBuilder)
await pyramid.connect(getDummySigner())
const [, alicePubKey, ,] = randomPrivateKey()
const [, bobPubKey, ,] = randomPrivateKey()
const aliceInstance = pyramid.next()
aliceInstance.schemer = PubKeyHash(toHex(alicePubKey))
const bobInstance = pyramid.next()
bobInstance.schemer = PubKeyHash(toHex(bobPubKey))
const { tx: callTx, atInputIndex } = await pyramid.methods.recruit(
PubKey(toHex(alicePubKey)),
PubKey(toHex(bobPubKey)),
{
fromUTXO: getDummyUTXO(),
changeAddress: myAddress,
} as MethodCallOptions<Pyramid>
)
const result = callTx.verifyScript(atInputIndex)
expect(result.success, result.error).to.eq(true)
}
describe('Test SmartContract Pyramid unit test', () => {
it('should succeed', async () => {
await main()
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment