From b13e33d67f734aaa53ea5fe9f6f584b4b471c54d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hern=C3=A1n=20Di=20Pietro?= Date: Mon, 15 Nov 2021 10:57:42 -0300 Subject: [PATCH] More setvphash call tests. --- lib/pricecaster.js | 14 +++++++++++--- test/wormhole-sc-test.js | 30 ++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/lib/pricecaster.js b/lib/pricecaster.js index 68d060ad..e2561cbf 100644 --- a/lib/pricecaster.js +++ b/lib/pricecaster.js @@ -505,16 +505,24 @@ class PricecasterLib { /** * Starts a begin...commit section for commiting grouped transactions. */ - this.beginVerifyTxGroup = async function () { + this.beginTxGroup = function () { this.groupTx = [] } /** - * @param {*} sender The sender account (typically the VAA verification stateless program) + * Adds a transaction to the group. + * @param {} tx Transaction to add. + */ + this.addTxToGroup = function (tx) { + this.groupTx.push(tx) + } + + /** + * @param {*} sender The sender account. * @param {function} signCallback The sign callback routine. * @returns Transaction id. */ - this.commitVerifyTxGroup = async function (sender, signCallback) { + this.commitTxGroup = async function (sender, signCallback) { algosdk.assignGroupID(this.groupTx) // Sign the transactions diff --git a/test/wormhole-sc-test.js b/test/wormhole-sc-test.js index 7c5e0041..b86c9291 100644 --- a/test/wormhole-sc-test.js +++ b/test/wormhole-sc-test.js @@ -117,13 +117,39 @@ describe('VAA Processor Smart-contract Tests', function () { expect(vphstate).to.equal(compiledProgram.hash) }) it('Must disallow setting stateless logic hash from non-owner', async function () { - + const teal = 'test/temp/vaa-verify.teal' + spawnSync('python', ['teal/wormhole/pyteal/vaa-verify.py', appId, teal]) + const program = fs.readFileSync(teal, 'utf8') + const compiledProgram = await pclib.compileProgram(program) + await expect(pclib.setVAAVerifyProgramHash(OTHER_ADDR, compiledProgram.hash, signCallback)).to.be.rejectedWith('Bad Request') }) it('Must reject setting stateless logic hash from group transaction', async function () { + const teal = 'test/temp/vaa-verify.teal' + spawnSync('python', ['teal/wormhole/pyteal/vaa-verify.py', appId, teal]) + const program = fs.readFileSync(teal, 'utf8') + const compiledProgram = await pclib.compileProgram(program) + const hash = algosdk.decodeAddress(compiledProgram.hash).publicKey + const appArgs = [new Uint8Array(Buffer.from('setvphash')), hash.subarray(0, 10)] + const params = await algodClient.getTransactionParams().do() + params.fee = 1000 + params.flatFee = true + + pclib.beginTxGroup() + const appTx = algosdk.makeApplicationNoOpTxn(OWNER_ADDR, params, this.appId, appArgs) + const dummyTx = algosdk.makeApplicationNoOpTxn(OWNER_ADDR, params, this.appId, appArgs) + pclib.addTxToGroup(appTx) + pclib.addTxToGroup(dummyTx) + await expect(pclib.commitTxGroup(OWNER_ADDR, signCallback)).to.be.rejectedWith('Bad Request') }) it('Must reject setting stateless logic hash with invalid address length', async function () { - + const teal = 'test/temp/vaa-verify.teal' + spawnSync('python', ['teal/wormhole/pyteal/vaa-verify.py', appId, teal]) + const program = fs.readFileSync(teal, 'utf8') + const compiledProgram = await pclib.compileProgram(program) + const hash = algosdk.decodeAddress(compiledProgram.hash).publicKey + const appArgs = [new Uint8Array(Buffer.from('setvphash')), hash.subarray(0, 10)] + await expect(pclib.callApp(OWNER_ADDR, appArgs, [], signCallback)).to.be.rejectedWith('Bad Request') }) it('Must verify and handle Pyth VAA', async function () {