Skip to content

Commit

Permalink
test: make fixtures configable & skip money-spending tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
nom4dv3 committed Jun 6, 2024
1 parent 2d3d926 commit 8da835b
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 50 deletions.
9 changes: 4 additions & 5 deletions tests/compile.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { describe, it } from 'vitest'
import { fixtures } from './fixureoptions'
import { fixtures } from './fixtures/fixureoptions'
import { testCompile } from './compile_test_impl'
import { config } from './config'

(global as any).__BROWSER__ = false

const pathfromfixtures = 'dsp/ethereum(storage)'
// const pathfromfixtures = 'dsp/ethereum(event)'
// const pathfromfixtures = 'dsp/ethereum.unsafe'
const option = fixtures[pathfromfixtures]
const fixtureKey = config.fixture
const option = fixtures[fixtureKey]

describe('test compile', async () => {
it('test compile', async () => {
Expand Down
5 changes: 5 additions & 0 deletions tests/config-example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ export const config = {
UserPrivateKey: '0x{key}',
CompilerServerEndpoint: DEFAULT_URL.COMPILER_SERVER,
ZkwasmProviderUrl: DEFAULT_URL.ZKWASMHUB,

// test config
fixture: 'dsp/ethereum(storage)',
// fixture: 'dsp/ethereum(event)',
proveTaskId: '65dd7dad235cd47b5193efce', // succ proof
}
2 changes: 1 addition & 1 deletion tests/deposit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { config } from './config'

(global as any).__BROWSER__ = false

it('test deposit', async () => {
it.skip('test deposit', async () => {
const rpcUrl = config.JsonRpcProviderUrl.sepolia
const provider = new ethers.providers.JsonRpcProvider(rpcUrl)
const deployedContractAddress = '0x870ef9B5DcBB6F71139a5f35D10b78b145853e69'
Expand Down
2 changes: 1 addition & 1 deletion tests/dispatch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { config } from './config'

(global as any).__BROWSER__ = false

it('test dispatch', async () => {
it.skip('test dispatch', async () => {
const queryAPI = 'https://zkwasm.hyperoracle.io/td'
const contractAddress = '0x5FbDB2315678afecb367f032d93F642f64180aa3'
const feeInWei = ethers.utils.parseEther('0.01')
Expand Down
10 changes: 5 additions & 5 deletions tests/dsp.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { describe, it } from 'vitest'
import { fixtures } from './fixureoptions'
import { fixtures } from './fixtures/fixureoptions'
import { testCompile } from './compile_test_impl'
import { testExecute } from './exec_test_impl'
import { config } from './config'

(global as any).__BROWSER__ = false

const pathfromfixtures = 'dsp/ethereum(storage)'
// const pathfromfixtures = 'dsp/ethereum.unsafe-ethereum'
const option = fixtures[pathfromfixtures]
const fixtureKey = config.fixture
const option = fixtures[fixtureKey]

describe(`test dsp: ${pathfromfixtures}`, () => {
describe(`test dsp: ${fixtureKey}`, () => {
it('test compile', async () => {
await testCompile(option)
}, { timeout: 100000 })
Expand Down
7 changes: 3 additions & 4 deletions tests/exec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import * as cleapi from '../src/index'
import { DSPNotFound } from '../src/common/error'
import { config } from './config'
import { loadYamlFromPath } from './utils/yaml'
import { fixtures } from './fixureoptions'
import { fixtures } from './fixtures/fixureoptions'
import { testExecute } from './exec_test_impl'

(global as any).__BROWSER__ = false

const pathfromfixtures = 'dsp/ethereum(storage)'
// const pathfromfixtures = 'dsp/ethereum.unsafe-ethereum'
const option = fixtures[pathfromfixtures]
const fixtureKey = config.fixture
const option = fixtures[fixtureKey]

// enable this to silence logs
// cleapi.setCLELogger(new cleapi.SilentLogger())
Expand Down
12 changes: 9 additions & 3 deletions tests/fixureoptions.ts → tests/fixtures/fixureoptions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { NetworksConfig } from '../src/common/utils'
import { config } from './config'
import type { NetworksConfig } from '../../src/common/utils'
import { config } from '../config'
// for storage case
import { getLatestBlocknumber } from './utils/ethers'
import { getLatestBlocknumber } from '../utils/ethers'

interface OptionType {
mappingPath: string
Expand Down Expand Up @@ -56,4 +56,10 @@ export const fixtures: Record<string, OptionType> = {
expectedState: '5c7a6cf20cbd3eef32e19b9cad4eca17c432a794000000005c7a6cf20cbd3eef32e19b9cad4eca17c432a794', // use event return
blocknum: eventblocknum,
},
'compile': {
...defaultPath('compile'),
local: false,
expectedState: '48656c6c6f20434c4520746573743221', // use event return
blocknum: eventblocknum,
},
}
17 changes: 11 additions & 6 deletions tests/prove.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import { loadConfigByNetwork } from '../src/common/utils'
import * as cleapi from '../src/index'
import { config } from './config'
import { loadYamlFromPath } from './utils/yaml'
import { fixtures } from './fixureoptions'
import { fixtures } from './fixtures/fixureoptions'

(global as any).__BROWSER__ = false

const pathfromfixtures = 'dsp/ethereum(storage)'
const option = fixtures[pathfromfixtures]
const fixtureKey = config.fixture
const option = fixtures[fixtureKey]
let proveTaskId: string

describe(`test prove ${pathfromfixtures}`, () => {
describe(`test prove ${fixtureKey}`, () => {
// console.log('issued a prove taslk: ', result)
it('test mock mode', async () => {
const { yamlPath, wasmPath, blocknum, expectedState } = option
Expand Down Expand Up @@ -44,7 +45,7 @@ describe(`test prove ${pathfromfixtures}`, () => {
)
console.log('mock result:', res)
}, { timeout: 100000 })
it.only('test prove mode', async () => {
it('test prove mode', async () => {
const { wasmPath, yamlPath, blocknum, expectedState } = option
const wasm = fs.readFileSync(wasmPath)
const wasmUint8Array = new Uint8Array(wasm)
Expand Down Expand Up @@ -83,11 +84,15 @@ describe(`test prove ${pathfromfixtures}`, () => {
})

console.log(result)

proveTaskId = result.taskId

expect(result.taskId).toBeTypeOf('string')
}, { timeout: 100000 })

it('test waitProve', async () => {
const taskId = '65dae256429af08ed922479a'
// use proveTaskId from "test prove mode" first
const taskId = proveTaskId || config.proveTaskId
const result = await cleapi.waitProve(config.ZkwasmProviderUrl, taskId as string, { batchStyle: cleapi.BatchStyle.ZKWASMHUB })
// console.log(result.proofParams?.instances)
expect((result.proofParams?.instances as any[])[0]).toBeInstanceOf(Array)
Expand Down
7 changes: 3 additions & 4 deletions tests/publish.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import * as cleapi from '../src/index'
import { abiFactory, addressFactory, cleContractABI } from '../src/common/constants'
import { config } from './config'
import { loadYamlFromPath } from './utils/yaml'
import { fixtures } from './fixureoptions'
import { fixtures } from './fixtures/fixureoptions'

(global as any).__BROWSER__ = false

const pathfromfixtures = 'dsp/ethereum(storage)'
// const pathfromfixtures = 'dsp/ethereum.unsafe-ethereum'
const option = fixtures[pathfromfixtures]
const fixtureKey = config.fixture
const option = fixtures[fixtureKey]

// enable this to silence logs
// cleapi.setCLELogger(new cleapi.SilentLogger())
Expand Down
2 changes: 1 addition & 1 deletion tests/rlp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { config } from './config'
(global as any).__BROWSER__ = false

describe('test rlp', async () => {
it('rlp', async () => {
it('blockheader rlp', async () => {
const rpcUrl = config.JsonRpcProviderUrl.sepolia
const provider = new ethers.providers.JsonRpcProvider(rpcUrl)

Expand Down
8 changes: 4 additions & 4 deletions tests/setup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { describe, it } from 'vitest'
import { ethers, providers } from 'ethers'
import * as cleapi from '../src/index'
import { config } from './config'
import { fixtures } from './fixureoptions'
import { fixtures } from './fixtures/fixureoptions'

(global as any).__BROWSER__ = false

const pathfromfixtures = 'dsp/ethereum(storage)'
const option = fixtures[pathfromfixtures]
const fixtureKey = config.fixture
const option = fixtures[fixtureKey]

describe('test setup', () => {
it('test setup', async () => {
Expand All @@ -23,5 +23,5 @@ describe('test setup', () => {
)
result
// console.log('test result', result)
}, { timeout: 10000 })
}, { timeout: 100000 })
})
13 changes: 4 additions & 9 deletions tests/trigger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,13 @@ import { ethers } from 'ethers'
import * as cleapi from '../src/index'
import { loadYamlFromPath } from './utils/yaml'
import { config } from './config'
import { fixtures } from './fixureoptions'
import { fixtures } from './fixtures/fixureoptions'

(global as any).__BROWSER__ = false

// const rpcUrl = 'https://rpc.ankr.com/eth_sepolia'

const pathfromfixtures = 'dsp/ethereum(storage)'
// const pathfromfixtures = 'dsp/ethereum.unsafe-ethereum'
const option = fixtures[pathfromfixtures]
// let ZkwasmProviderUrl = "https://zkwasm-explorer.delphinuslab.com:8090"
const proveTaskId = '65dd7dad235cd47b5193efce' // true
// const proveTaskId = '655568eaadb2c56ffd2f0ee0' // fasle
const fixtureKey = config.fixture
const option = fixtures[fixtureKey]
const proveTaskId = config.proveTaskId

// TODO: use a reward == 0 cle to pass trigger test

Expand Down
6 changes: 3 additions & 3 deletions tests/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as cleapi from '../src/index'
import { u32ListToUint8Array } from '../src/common/utils'
import { config } from './config'
import { loadYamlFromPath } from './utils/yaml'
import { fixtures } from './fixureoptions'
import { fixtures } from './fixtures/fixureoptions'

(global as any).__BROWSER__ = false

Expand All @@ -34,11 +34,11 @@ describe('test utils', () => {
})

it('yaml filterSections', () => {
const yaml = loadYamlFromPath(fixtures['dsp/ethereum(event)'].yamlPath) as any
const yaml = loadYamlFromPath(fixtures[config.fixture].yamlPath) as any
expect(yaml.dataSources[0].filterByKeys(['event', 'storage']).event).toBeInstanceOf(Array)
})
it('yaml toString', () => {
const yamlpath = fixtures['dsp/ethereum(event)'].yamlPath
const yamlpath = fixtures[config.fixture].yamlPath
const yamlContents = fs.readFileSync(yamlpath, 'utf8')
const expectedYamlDump = yaml.dump(yaml.load(yamlContents))

Expand Down
7 changes: 3 additions & 4 deletions tests/verify.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import { ethers } from 'ethers'
import * as cleapi from '../src/index'
import { AggregatorVerifierAddress } from '../src/common/constants'
import { loadYamlFromPath } from './utils/yaml'
import { fixtures } from './fixureoptions'
import { fixtures } from './fixtures/fixureoptions'
import { config } from './config'

(global as any).__BROWSER__ = false

const yamlPath = fixtures['dsp/ethereum(event)'].yamlPath
// const proveTaskId = 'v4YpdX4UufG89z2CwA26m0OS' // ora prover proof
const proveTaskId = '65dd7dad235cd47b5193efce' // zkwasmhub proof
const yamlPath = fixtures[config.fixture].yamlPath
const proveTaskId = config.proveTaskId

describe('test verify', () => {
const cleYaml = loadYamlFromPath(yamlPath)
Expand Down

0 comments on commit 8da835b

Please sign in to comment.