Skip to content

Commit

Permalink
test(cli): update cost model tests for single/multi network mode
Browse files Browse the repository at this point in the history
Signed-off-by: Alexis Asseman <[email protected]>
  • Loading branch information
aasseman committed May 25, 2024
1 parent db0fd13 commit 01934d3
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 14 deletions.
4 changes: 2 additions & 2 deletions packages/indexer-cli/src/__tests__/cli.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { cliTest, setup, teardown } from './util'
import { cliTest, setupMultiNetworks, teardown } from './util'
import path from 'path'

const baseDir = path.join(__dirname)

describe('Indexer cli tests', () => {
beforeEach(setup)
beforeEach(setupMultiNetworks)
afterEach(teardown)

describe('General', () => {
Expand Down
10 changes: 8 additions & 2 deletions packages/indexer-cli/src/__tests__/indexer/actions.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { cliTest, deleteFromAllTables, seedActions, setup, teardown } from '../util'
import {
cliTest,
deleteFromAllTables,
seedActions,
setupMultiNetworks,
teardown,
} from '../util'
import path from 'path'

const baseDir = path.join(__dirname, '..')
describe('Indexer actions tests', () => {
describe('With indexer management server', () => {
beforeAll(setup)
beforeAll(setupMultiNetworks)
afterAll(teardown)
beforeEach(seedActions)
afterEach(deleteFromAllTables)
Expand Down
51 changes: 48 additions & 3 deletions packages/indexer-cli/src/__tests__/indexer/cost.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import {
cliTest,
setup,
teardown,
connect,
deleteFromAllTables,
seedCostModels,
setupSingleNetwork,
setupMultiNetworks,
} from '../util'
import path from 'path'

const baseDir = path.join(__dirname, '..')

describe('Indexer cost tests', () => {
describe('Indexer cost tests singleNetwork', () => {
describe('With indexer management server', () => {
beforeAll(setup)
beforeAll(setupSingleNetwork)
afterAll(teardown)
beforeEach(seedCostModels)
afterEach(deleteFromAllTables)
Expand Down Expand Up @@ -231,3 +232,47 @@ describe('Indexer cost tests', () => {
)
})
})

describe('Indexer cost tests multiNetworks', () => {
beforeAll(setupMultiNetworks)
afterAll(teardown)
beforeEach(seedCostModels)
afterEach(deleteFromAllTables)

describe('Cost set...', () => {
cliTest(
'Indexer cost set model deployment id - reject multinetwork mode',
[
'indexer',
'cost',
'set',
'model',
'QmXRpJW3qBuYaiBYHdhv8DF4bHDZhXBmh91MtrnhJfQ5Lk',
'references/basic.agora',
],
'references/indexer-cost-model-deployment-multinetworks',
{
expectedExitCode: 1,
cwd: baseDir,
timeout: 10000,
},
)
cliTest(
'Indexer cost set variable deployment id - reject multinetwork mode',
[
'indexer',
'cost',
'set',
'variables',
'QmQ44hgrWWt3Qf2X9XEX2fPyTbmQbChxwNm5c1t4mhKpGt',
`'{"DAI": "0.5"}'`,
],
'references/indexer-cost-variables-deployment-multinetworks',
{
expectedExitCode: 1,
cwd: baseDir,
timeout: 10000,
},
)
})
})
4 changes: 2 additions & 2 deletions packages/indexer-cli/src/__tests__/indexer/rules.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import {
cliTest,
connect,
setup,
teardown,
deleteFromAllTables,
seedIndexingRules,
setupMultiNetworks,
} from '../util'
import path from 'path'

const baseDir = path.join(__dirname, '..')

describe('Indexer rules tests', () => {
describe('With indexer management server', () => {
beforeAll(setup)
beforeAll(setupMultiNetworks)
afterAll(teardown)
beforeEach(seedIndexingRules)
afterEach(deleteFromAllTables)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[GraphQL] Must be in single network mode to set cost models
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[GraphQL] Must be in single network mode to set cost models
20 changes: 15 additions & 5 deletions packages/indexer-cli/src/__tests__/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,15 @@ export const testNetworkSpecification = specification.NetworkSpecification.parse
},
})

export const setup = async () => {
export const setupMultiNetworks = async () => {
return await setup(true)
}

export const setupSingleNetwork = async () => {
return await setup(false)
}

export const setup = async (multiNetworksEnabled: boolean) => {
logger = createLogger({
name: 'Setup',
async: false,
Expand Down Expand Up @@ -141,10 +149,12 @@ export const setup = async () => {
const fakeMainnetNetwork = cloneDeep(network) as Network
fakeMainnetNetwork.specification.networkIdentifier = 'eip155:1'

const multiNetworks = new MultiNetworks(
[network, fakeMainnetNetwork],
(n: Network) => n.specification.networkIdentifier,
)
const multiNetworks = multiNetworksEnabled
? new MultiNetworks(
[network, fakeMainnetNetwork],
(n: Network) => n.specification.networkIdentifier,
)
: new MultiNetworks([network], (n: Network) => n.specification.networkIdentifier)

const defaults: IndexerManagementDefaults = {
globalIndexingRule: {
Expand Down

0 comments on commit 01934d3

Please sign in to comment.