Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(builder): add test cases for action filter test based on standard schema #278

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sweet-insects-remember.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rabbitholegg/create-plugin": minor
---

add standardized test for valid action filter
47 changes: 45 additions & 2 deletions apps/create-plugin/template/src/Project.test.ts.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,51 @@ import { {{actionType}} } from './{{capitalize projectName}}'
describe('Given the {{lowercase projectName}} plugin', () => {
describe('When handling the {{actionType}} action', () => {
describe('should return a valid action filter', () => {
// test that a valid filter is returned, check the link for a specific example from the sound.xyz package
// https://github.com/rabbitholegg/questdk-plugins/blob/6c7c91c6f6393e15f0bb58558ad0edb2c79a77ff/packages/soundxyz/src/Soundxyz.test.ts#L14-L34
test('when making a valid {{actionType}} action', async () => {
const filter = await {{actionType}}({
{{#eq actionType 'bridge'}}
sourceChainId: 1,
destinationChainId: 10,
{{else}}
{{#eq actionType 'mint'}}
chainId: 1,
contractAddress: '0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF',
{{else}}
{{#eq actionType 'burn'}}
chainId: 1,
contractAddress: '0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF',
{{else}}
{{#eq actionType 'delegate'}}
chainId: 1,
project: '0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF',
{{else}}
{{#eq actionType 'vote'}}
chainId: 1,
project: '0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF',
{{else}}
chainId: 1,
{{/eq}}
{{/eq}}
{{/eq}}
{{/eq}}
{{/eq}}
})
expect(filter).toBeTypeOf('object')
expect(['string', 'number']).toContain(typeof filter.chainId)
expect(Number(filter.chainId)).toBe(1)
if (typeof filter.to === 'string') {
expect(filter.to).toMatch(/^0x[a-fA-F0-9]{40}$/)
} else {
// if to is an object, it should have a logical operator as the only key
expect(filter.to).toBeTypeOf('object')
expect(Object.keys(filter.to)).toHaveLength(1)
expect(['$or', '$and'].some(prop => Object.hasOwnProperty.call(filter.to, prop))).to.be.true
expect(Object.values(filter.to)[0]).to.satisfy((arr: string[]) => arr.every((val) => val.match(/^0x[a-fA-F0-9]{40}$/)))
}
// Check the input property is the correct type and has a valid $abi operator
expect(filter.input).toBeTypeOf('object')
expect(['$abi', '$abiParams', '$abiAbstract','$or', '$and'].some(prop => Object.hasOwnProperty.call(filter.input, prop))).to.be.true
})
})

describe('should pass filter with valid transactions', () => {
Expand Down
Loading