Testing WIP
This commit is contained in:
parent
16b4f79115
commit
8744107183
|
@ -1,3 +1,4 @@
|
|||
const { encodeAddress } = require('algosdk')
|
||||
const algosdk = require('algosdk')
|
||||
const fs = require('fs')
|
||||
// eslint-disable-next-line camelcase
|
||||
|
@ -6,8 +7,8 @@ const tools = require('../tools/app-tools')
|
|||
|
||||
const approvalProgramFilename = 'teal/pricekeeper/pricekeeper.teal'
|
||||
const clearProgramFilename = 'teal/pricekeeper/clearstate.teal'
|
||||
const vaaProcessorApprovalProgramFilename = 'teal/wormhole/build/vaa-processor-approval.teal'
|
||||
const vaaProcessorClearProgramFilename = 'teal/wormhole/build/vaa-processor-clear.teal'
|
||||
let vaaProcessorApprovalProgramFilename = 'teal/wormhole/build/vaa-processor-approval.teal'
|
||||
let vaaProcessorClearProgramFilename = 'teal/wormhole/build/vaa-processor-clear.teal'
|
||||
const vaaVerifyStatelessProgramFilename = 'teal/wormhole/build/vaa-verify.teal'
|
||||
|
||||
class PricecasterLib {
|
||||
|
@ -16,6 +17,20 @@ class PricecasterLib {
|
|||
this.ownerAddr = ownerAddr
|
||||
this.minFee = 1000
|
||||
|
||||
/** Overrides the default VAA processor approval program filename
|
||||
* @param {string} filename New file name to use.
|
||||
*/
|
||||
this.setVaaProcessorApprovalFile = function (filename) {
|
||||
vaaProcessorApprovalProgramFilename = filename
|
||||
}
|
||||
|
||||
/** Overrides the default VAA processor clear-state program filename
|
||||
* @param {string} filename New file name to use.
|
||||
*/
|
||||
this.setVaaProcessorClearStateFile = function (filename) {
|
||||
vaaProcessorClearProgramFilename = filename
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Application Id used in all the functions of this class.
|
||||
* @param {number} applicationId application id
|
||||
|
@ -470,6 +485,25 @@ class PricecasterLib {
|
|||
appArgs.push(new Uint8Array(msgBuffer))
|
||||
return await this.callAppInDummyGroup(sender, appArgs, [], signCallback, 3)
|
||||
}
|
||||
|
||||
/**
|
||||
* VAA Processor: Sets the stateless logic program hash
|
||||
* @param {*} sender Sender account
|
||||
* @param {*} hash The stateless logic program hash
|
||||
* @returns Transaction identifier.
|
||||
*/
|
||||
this.setVAAVerifyProgramHash = async function (sender, hash, signCallback) {
|
||||
if (!algosdk.isValidAddress(sender)) {
|
||||
throw new Error('Invalid sender address: ' + sender)
|
||||
}
|
||||
if (!algosdk.isValidAddress(hash)) {
|
||||
throw new Error('Invalid program hash: ' + hash)
|
||||
}
|
||||
const appArgs = []
|
||||
appArgs.push(new Uint8Array(Buffer.from('setvphash')),
|
||||
algosdk.decodeAddress(hash).publicKey)
|
||||
return await this.callApp(sender, appArgs, [], signCallback)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,8 +10,8 @@
|
|||
"start-btc": "npm run compile && cross-env PRICECASTER_SETTINGS=./settings/settings-btc.js node build/main.js",
|
||||
"start-eth": "npm run compile && cross-env PRICECASTER_SETTINGS=./settings/settings-eth.js node build/main.js",
|
||||
"start-doge": "npm run compile && cross-env PRICECASTER_SETTINGS=./settings/settings-doge.js node build/main.js",
|
||||
"test-pkeeper-sc": "mocha test/pkeeper-sc-test.js --timeout 60000",
|
||||
"test-wormhole-sc": "mocha test/wormhole-sc-test.js --timeout 60000"
|
||||
"test-pkeeper-sc": "mocha test/pkeeper-sc-test.js --timeout 60000 --bail",
|
||||
"test-wormhole-sc": "mocha test/wormhole-sc-test.js --timeout 60000 --bail"
|
||||
},
|
||||
"author": "Randlabs inc",
|
||||
"license": "ISC",
|
||||
|
|
|
@ -44,6 +44,7 @@ from pyteal.types import *
|
|||
from pyteal.compiler import *
|
||||
from pyteal.ir import *
|
||||
from globals import *
|
||||
import sys
|
||||
|
||||
GUARDIAN_ADDRESS_SIZE = 20
|
||||
METHOD = Txn.application_args[0]
|
||||
|
@ -251,6 +252,12 @@ if __name__ == "__main__":
|
|||
|
||||
approval_outfile = "teal/wormhole/build/vaa-processor-approval.teal"
|
||||
clear_state_outfile = "teal/wormhole/build/vaa-processor-clear.teal"
|
||||
|
||||
if len(sys.argv) >= 2:
|
||||
approval_outfile = sys.argv[1]
|
||||
|
||||
if len(sys.argv) >= 3:
|
||||
clear_state_outfile = sys.argv[2]
|
||||
|
||||
print("VAA Processor Program, (c) 2021-22 Randlabs Inc. ")
|
||||
print("Compiling approval program...")
|
||||
|
|
|
@ -81,17 +81,21 @@ def vaa_verify_program(vaa_processor_app_id):
|
|||
|
||||
|
||||
if __name__ == "__main__":
|
||||
outfile = "teal/wormhole/build/vaa-verify.teal"
|
||||
appid = 0
|
||||
|
||||
print("VAA Verify Stateless Program, (c) 2021-22 Randlabs Inc. ")
|
||||
print("Compiling...")
|
||||
if len(sys.argv) != 2:
|
||||
print ("No appid argument provided")
|
||||
exit(1)
|
||||
|
||||
outfile = "teal/wormhole/build/vaa-verify.teal"
|
||||
if len(sys.argv) >= 2:
|
||||
appid = sys.argv[1]
|
||||
|
||||
if len(sys.argv) >= 3:
|
||||
outfile = sys.argv[2]
|
||||
|
||||
with open(outfile, "w") as f:
|
||||
compiled = compileTeal(vaa_verify_program(
|
||||
int(sys.argv[1])), mode=Mode.Signature, version=5)
|
||||
int(appid)), mode=Mode.Signature, version=5)
|
||||
f.write(compiled)
|
||||
|
||||
print("Written to " + outfile)
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
dummy file
|
|
@ -5,6 +5,10 @@ const algosdk = require('algosdk')
|
|||
const { expect } = require('chai')
|
||||
const chai = require('chai')
|
||||
chai.use(require('chai-as-promised'))
|
||||
const spawnSync = require('child_process').spawnSync
|
||||
const fs = require('fs')
|
||||
let pclib
|
||||
let algodClient
|
||||
|
||||
const OWNER_ADDR = 'OPDM7ACAW64Q4VBWAL77Z5SHSJVZZ44V3BAN7W44U43SUXEOUENZMZYOQU'
|
||||
const OWNER_MNEMO = 'assault approve result rare float sugar power float soul kind galaxy edit unusual pretty tone tilt net range pelican avoid unhappy amused recycle abstract master'
|
||||
|
@ -14,23 +18,50 @@ const SIGNATURES = {}
|
|||
SIGNATURES[OWNER_ADDR] = algosdk.mnemonicToSecretKey(OWNER_MNEMO)
|
||||
SIGNATURES[OTHER_ADDR] = algosdk.mnemonicToSecretKey(OTHER_MNEMO)
|
||||
|
||||
const gkeys = [
|
||||
'13947Bd48b18E53fdAeEe77F3473391aC727C638',
|
||||
'F18AbBac073741DD0F002147B735Ff642f3D113F',
|
||||
'9925A94DC043D0803f8ef502D2dB15cAc9e02D76',
|
||||
'9e4EC2D92af8602bCE74a27F99A836f93C4a31E4',
|
||||
'9C40c4052A3092AfB8C99B985fcDfB586Ed19c98',
|
||||
'B86020cF1262AA4dd5572Af76923E271169a2CA7',
|
||||
'1937617fE1eD801fBa14Bd8BB9EDEcBA7A942FFe',
|
||||
'9475b8D45DdE53614d92c779787C27fE2ef68752',
|
||||
'15A53B22c28AbC7B108612146B6aAa4a537bA305',
|
||||
'63842657C7aC7e37B04FBE76b8c54EFe014D04E1',
|
||||
'948ca1bBF4B858DF1A505b4C69c5c61bD95A12Bd',
|
||||
'A6923e2259F8B5541eD18e410b8DdEE618337ff0',
|
||||
'F678Daf4b7f2789AA88A081618Aa966D6a39e064',
|
||||
'8cF31021838A8B3fFA43a71a50609877846f9E6d',
|
||||
'eB15bCF2ae4f957012330B4741ecE3242De96184',
|
||||
'cc3766a03e4faec44Bda7a46D9Ea2A9D124e9Bf8',
|
||||
'841f499Ba89a6a8E9dD273BAd82Beb175094E5d7',
|
||||
'f5F2b82576e6CA17965dee853d08bbB471FA2433',
|
||||
'2bC2B1204599D4cA0d4Dde4a658a42c4dD13103a'
|
||||
]
|
||||
|
||||
function makeVAA () {
|
||||
|
||||
}
|
||||
|
||||
async function createApp (gsexptime, gkeys) {
|
||||
const txId = await pclib.createVaaProcessorApp(OWNER_ADDR, gsexptime, gkeys.join(''), signCallback)
|
||||
const txResponse = await pclib.waitForTransactionResponse(txId)
|
||||
const appId = pclib.appIdFromCreateAppResponse(txResponse)
|
||||
pclib.setAppId(appId)
|
||||
return appId
|
||||
}
|
||||
|
||||
function signCallback (sender, tx) {
|
||||
const txSigned = tx.signTxn(SIGNATURES[sender].sk)
|
||||
return txSigned
|
||||
}
|
||||
|
||||
describe('VAA Processor Smart-contract Tests', function () {
|
||||
let pclib
|
||||
let algodClient
|
||||
let appId
|
||||
let lastTs
|
||||
|
||||
before(async function () {
|
||||
algodClient = new algosdk.Algodv2('', 'https://api.betanet.algoexplorer.io', '')
|
||||
algodClient = new algosdk.Algodv2('', 'https://api.testnet.algoexplorer.io', '')
|
||||
pclib = new PricecasterLib.PricecasterLib(algodClient)
|
||||
|
||||
console.log('Clearing accounts of all previous apps...')
|
||||
|
@ -45,62 +76,85 @@ describe('VAA Processor Smart-contract Tests', function () {
|
|||
}
|
||||
}
|
||||
|
||||
// console.log('Creating new app...')
|
||||
// const txId = await pclib.createApp(OWNER_ADDR, OWNER_ADDR, VALID_SYMBOL, signCallback)
|
||||
// const txResponse = await pclib.waitForTransactionResponse(txId)
|
||||
// appId = pclib.appIdFromCreateAppResponse(txResponse)
|
||||
// pclib.setAppId(appId)
|
||||
// console.log('App Id: %d', appId)
|
||||
const vaaProcessorClearState = 'test/temp/vaa-clear-state.teal'
|
||||
const vaaProcessorApproval = 'test/temp/vaa-processor.teal'
|
||||
|
||||
pclib.setVaaProcessorApprovalFile(vaaProcessorApproval)
|
||||
pclib.setVaaProcessorClearStateFile(vaaProcessorClearState)
|
||||
console.log(spawnSync('python', ['teal/wormhole/pyteal/vaa-processor.py', vaaProcessorApproval, vaaProcessorClearState]).output.toString())
|
||||
}
|
||||
)
|
||||
it('Must fail to create app without arguments', async function () {
|
||||
it('Must fail to create app with incorrect guardian keys length', async function () {
|
||||
const gsexptime = 2524618800
|
||||
await expect(createApp(gsexptime, ['BADADDRESS'])).to.be.rejectedWith('Bad Request')
|
||||
})
|
||||
it('Must create app with initial guardians and proper initial state', async function () {
|
||||
const gsexptime = 2524618800
|
||||
appId = await createApp(gsexptime, gkeys)
|
||||
console.log(' [Created appId: %d]', appId)
|
||||
|
||||
}),
|
||||
it('Must fail to create app with incorrect argument length', async function () {
|
||||
const gscount = await tools.readAppGlobalStateByKey(algodClient, appId, OWNER_ADDR, 'gscount')
|
||||
const gsexp = await tools.readAppGlobalStateByKey(algodClient, appId, OWNER_ADDR, 'gsexp')
|
||||
expect(gscount.toString()).to.equal((gkeys.length).toString())
|
||||
expect(gsexp.toString()).to.equal(gsexptime.toString())
|
||||
|
||||
}),
|
||||
it('Must fail to create app with incorrect length', async function () {
|
||||
|
||||
}),
|
||||
it('Must create app with initial guardians', async function () {
|
||||
|
||||
}),
|
||||
let i = 0
|
||||
const buf = Buffer.alloc(8)
|
||||
for (const gk of gkeys) {
|
||||
buf.writeBigUint64BE(BigInt(i++))
|
||||
const gkstate = await tools.readAppGlobalStateByKey(algodClient, appId, OWNER_ADDR, buf.toString())
|
||||
expect(Buffer.from(gkstate, 'base64').toString('hex')).to.equal(gk.toLowerCase())
|
||||
}
|
||||
})
|
||||
it('Must set stateless logic hash from 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)
|
||||
const txid = await pclib.setVAAVerifyProgramHash(OWNER_ADDR, compiledProgram.hash, signCallback)
|
||||
await pclib.waitForTransactionResponse(txid)
|
||||
const vphstate = await tools.readAppGlobalStateByKey(algodClient, appId, OWNER_ADDR, 'vphash')
|
||||
expect(algosdk.encodeAddress(Buffer.from(vphstate, 'base64'))).to.equal(compiledProgram.hash)
|
||||
})
|
||||
it('Must disallow setting stateless logic hash from non-owner', async function () {
|
||||
|
||||
}),
|
||||
it('Must set stateless logic hash from owner', async function () {
|
||||
})
|
||||
it('Must reject setting stateless logic hash from group transaction', async function () {
|
||||
|
||||
}),
|
||||
})
|
||||
it('Must reject setting stateless logic hash with invalid address length', async function () {
|
||||
|
||||
})
|
||||
it('Must verify and handle Pyth VAA', async function () {
|
||||
|
||||
}),
|
||||
})
|
||||
it('Must verify and handle governance VAA', async function () {
|
||||
|
||||
}),
|
||||
})
|
||||
it('Must reject unknown VAA', async function () {
|
||||
|
||||
}),
|
||||
})
|
||||
it('Must reject incorrect transaction group size', async function () {
|
||||
|
||||
}),
|
||||
})
|
||||
it('Must reject incorrect argument count for verify call', async function () {
|
||||
|
||||
}),
|
||||
})
|
||||
it('Must reject unknown sender for verify call', async function () {
|
||||
|
||||
}),
|
||||
})
|
||||
it('Must reject guardian set count argument not matching global state', async function () {
|
||||
|
||||
}),
|
||||
})
|
||||
it('Must reject guardian key list argument not matching global state', async function () {
|
||||
|
||||
}),
|
||||
})
|
||||
it('Must reject non-app call transaction in group', async function () {
|
||||
|
||||
}),
|
||||
})
|
||||
it('Must reject app-call with mismatched AppId in group', async function () {
|
||||
|
||||
}),
|
||||
})
|
||||
it('Must reject transaction with not verified bit set in group', async function () {
|
||||
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue