Skip to content

Commit

Permalink
Testing (#29)
Browse files Browse the repository at this point in the history
* appky patch

* change url for testing

* update url

* setup action

* setup actions for testing

* simulate new plugin
  • Loading branch information
mmackz authored Mar 3, 2024
1 parent 0e98b1d commit e23eedf
Show file tree
Hide file tree
Showing 12 changed files with 232 additions and 1 deletion.
15 changes: 15 additions & 0 deletions packages/firsttest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## FirstTest Plugin for Boost

### New Plugin TODO list

1. Find the ABI of the function your transaction is calling, and add export it as a const in the abi.ts file
1. this can be multiple ABIs, if the transaction is calling multiple functions
2. in FirstTest.ts, fill out each Action function by mapping the ActionParams to the ABI of the function



### Actions and Descriptions



### Example Transactions
42 changes: 42 additions & 0 deletions packages/firsttest/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "@rabbitholegg/questdk-plugin-firsttest",
"private": true,
"version": "1.0.0-alpha.0",
"type": "module",
"exports": {
"require": "./dist/cjs/index.js",
"import": "./dist/esm/index.js",
"types": "./dist/types/index.d.ts"
},
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"description": "Plugin for firstTest",
"scripts": {
"bench": "vitest bench",
"bench:ci": "CI=true vitest bench",
"build": "pnpm run clean && pnpm run build:cjs && pnpm run build:esm && pnpm run build:types",
"build:cjs": "tsc --project tsconfig.build.json --module commonjs --outDir ./dist/cjs --removeComments --verbatimModuleSyntax false && echo > ./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
"build:esm": "tsc --project tsconfig.build.json --module es2015 --outDir ./dist/esm && echo > ./dist/esm/package.json '{\"type\":\"module\",\"sideEffects\":false}'",
"build:types": "tsc --project tsconfig.build.json --module esnext --declarationDir ./dist/types --emitDeclarationOnly --declaration --declarationMap",
"clean": "rimraf dist",
"format": "rome format . --write",
"lint": "rome check .",
"lint:fix": "pnpm lint --apply",
"test": "vitest dev",
"test:cov": "vitest dev --coverage",
"test:ci": "CI=true vitest --coverage",
"test:ui": "vitest dev --ui"
},
"keywords": [],
"author": "",
"license": "ISC",
"types": "./dist/types/index.d.ts",
"typings": "./dist/types/index.d.ts",
"devDependencies": {
"tsconfig": "workspace:*"
},
"dependencies": {
"@rabbitholegg/questdk-plugin-utils": "workspace:*",
"@rabbitholegg/questdk": "workspace:*"
}
}
12 changes: 12 additions & 0 deletions packages/firsttest/plugin-details.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
project:
name: FirstTest
iconOption: https://assets.coingecko.com/coins/images/6319/standard/usdc.png
appLink: https://firsttest.xyz

task:
# action specific name, this is what will show as the default title for your boosts
name: Mint on FirstTest
# action specific link to your project. (ie: myapp.com/mint)
link: https://firsttest.xyz/mint
iconOption: https://assets.coingecko.com/coins/images/6319/standard/usdc.png
actionPluginId: mint
29 changes: 29 additions & 0 deletions packages/firsttest/src/FirstTest.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { apply } from '@rabbitholegg/questdk/filter'
import { describe, expect, test } from 'vitest'
import { passingTestCases, failingTestCases } from './test-transactions'
import { mint } from './FirstTest'

describe('Given the firsttest plugin', () => {
describe('When handling the mint action', () => {

describe('should pass filter with valid transactions', () => {
passingTestCases.forEach((testCase) => {
const { transaction, description, params } = testCase
test(description, async () => {
const filter = await mint(params)
expect(apply(transaction, filter)).to.be.false
})
})
})

describe('should not pass filter with invalid transactions', () => {
failingTestCases.forEach((testCase) => {
const { transaction, description, params } = testCase
test(description, async () => {
const filter = await mint(params)
expect(apply(transaction, filter)).to.be.false
})
})
})
})
})
46 changes: 46 additions & 0 deletions packages/firsttest/src/FirstTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {
type TransactionFilter,
type MintActionParams,
compressJson,
} from '@rabbitholegg/questdk'
import { type Address } from 'viem'

/*
* Function templates for handling various blockchain action types.
* It's adaptable for actions defined in ActionParams: Bridge, Swap, Stake, Mint, Delegate, Quest, Etc.
* Duplicate and customize for each specific action type.
* If you wish to use a different action other than swap, import one of the ActionParams types
* from @rabbitholegg/questdk (ie: SwapActionParams) and change the function below to use
* the action params you wish to use.
*/

export const mint = async(_params: MintActionParams): Promise<TransactionFilter> => {

// the ActionParams for this function are populated in the Boost Manager when the actual Boost is launched.

// In this function you should load the ABI, and translate any ActionParams into the input object defined below
// which should match the parameter names in the transaction

// You can also use the boostdk filter system to support operators on parameters, for example, greater than


// We always want to return a compressed JSON object which we'll transform into a TransactionFilter
return compressJson({
chainId: '0x0',
to: '0x0', // The to field is the address of the contract we're interacting with
input: {}, // The input object is where we'll put the ABI and the parameters
})

}

export const getSupportedTokenAddresses = async (
_chainId: number,
): Promise<Address[]> => {
// Given a specific chain we would expect this function to return a list of supported token addresses
return []
}

export const getSupportedChainIds = async (): Promise<number[]> => {
// This should return all of the ChainIds that are supported by the Project we're integrating
return []
}
16 changes: 16 additions & 0 deletions packages/firsttest/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {
type IActionPlugin,
} from '@rabbitholegg/questdk'

import {
mint,
getSupportedChainIds,
getSupportedTokenAddresses,
} from './FirstTest.js'

export const FirstTest: IActionPlugin = {
pluginId: "firsttest",
getSupportedTokenAddresses,
getSupportedChainIds,
mint,
}
29 changes: 29 additions & 0 deletions packages/firsttest/src/test-transactions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { type MintActionParams } from '@rabbitholegg/questdk'
import {
createTestCase,
type TestParams,
} from '@rabbitholegg/questdk-plugin-utils'

// values are placeholders, replace with actual values from your test transaction
export const MINT_TEST: TestParams<MintActionParams> = {
transaction: {
chainId: 1,
from: '0x0',
hash: '0x0',
input: '0x0',
to: '0x0',
value: '0',
},
params: {
chainId: 0,
contractAddress: '0x0',
},
}

export const passingTestCases = [
createTestCase(MINT_TEST, 'this is a demo test'),
]

export const failingTestCases = [
createTestCase(MINT_TEST, 'when chainId is not correct', { chainId: 99 }),
]
18 changes: 18 additions & 0 deletions packages/firsttest/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": "tsconfig/base.json",
"include": ["src"],
"exclude": [
"src/**/*.test.ts",
"src/**/*.test-d.ts",
"src/**/*.bench.ts",
"src/_test",
"scripts/**/*"
],
"compilerOptions": {
"declaration": true,
"declarationDir": "./dist/types",
"resolveJsonModule": true,
"sourceMap": true,
"rootDir": "./src"
}
}
5 changes: 5 additions & 0 deletions packages/firsttest/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "tsconfig/base.json",
"include": ["src/**/*", "src/chain-data.ts"],
"exclude": ["dist", "build", "node_modules"]
}
3 changes: 2 additions & 1 deletion packages/registry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"@rabbitholegg/questdk-plugin-llama": "workspace:*",
"@rabbitholegg/questdk-plugin-boost": "workspace:*",
"@rabbitholegg/questdk-plugin-kote": "workspace:*",
"@rabbitholegg/questdk-plugin-jojo": "workspace:*"
"@rabbitholegg/questdk-plugin-jojo": "workspace:*",
"@rabbitholegg/questdk-plugin-firsttest": "workspace:*"
}
}
2 changes: 2 additions & 0 deletions packages/registry/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { Vela } from '@rabbitholegg/questdk-plugin-vela'
import { WooFi } from '@rabbitholegg/questdk-plugin-woofi'
import { Zora } from '@rabbitholegg/questdk-plugin-zora'
import { JOJO } from '@rabbitholegg/questdk-plugin-jojo'
import { FirstTest } from '@rabbitholegg/questdk-plugin-firsttest'
import { ENTRYPOINT } from './contract-addresses'
import {
type IntentParams,
Expand Down Expand Up @@ -85,6 +86,7 @@ export const plugins: Record<string, IActionPlugin> = {
[Llama.pluginId]: Llama,
[Kote.pluginId]: Kote,
[JOJO.pluginId]: JOJO,
[FirstTest.pluginId]: FirstTest,
}

export const getPlugin = (pluginId: string) => {
Expand Down
16 changes: 16 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e23eedf

Please sign in to comment.