Skip to content

Commit

Permalink
test passing with node env on jest
Browse files Browse the repository at this point in the history
  • Loading branch information
Ptroger committed Jan 18, 2024
1 parent c2ea2a8 commit 6a89f88
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// type Hex = `0x${string}`

describe('decode', () => {
describe('transaction request input', () => {
describe('transfers', () => {
it('pass', () => {
expect(true).toBeTruthy()
})
// it('should decode erc20 transfer', () => {
// const input: TransactionInput = {
// type: InputType.TRANSACTION_REQUEST,
// txRequest: {
// to: '0x031d8C0cA142921c459bCB28104c0FF37928F9eD',
// data: `${Erc20Methods.TRANSFER}000000000000000000000000fe8f4de6e39c523ced231e7a72628f58e0ffee71000000000000000000000000000000000000000000000000000000000007a120` as Hex,
// from: '0xEd123cf8e3bA51c6C15DA1eAc74B2b5DEEA31448',
// chainId: '137',
// nonce: 10
// }
// }
// const decoded = decode(input)
// const expected: TransferErc20 = {
// type: Intents.TRANSFER_ERC20,
// contract: 'eip155:137:0x031d8C0cA142921c459bCB28104c0FF37928F9eD' as Caip10,
// to: 'eip155:137:0xfe8f4de6e39c523ced231e7a72628f58e0ffee71' as Caip10,
// from: 'eip155:137:0xEd123cf8e3bA51c6C15DA1eAc74B2b5DEEA31448' as Caip10,
// amount: '500000000000000000000'
// }
// expect(decoded).toEqual(expected)
// })
// it('should decode erc20 transferFrom with contract registry', () => {
// const contractRegistry = {
// 'eip155:137:0x031d8C0cA142921c459bCB28104c0FF37928F9eD': AssetTypeEnum.ERC20
// } as ContractRegistry
// const input: TransactionInput = {
// type: InputType.TRANSACTION_REQUEST,
// txRequest: {
// to: '0x031d8C0cA142921c459bCB28104c0FF37928F9eD',
// data: `${Erc20Methods.TRANSFER_FROM}000000000000000000000000fe8f4de6e39c523ced231e7a72628f58e0ffee71000000000000000000000000000000000000000000000000000000000007a120` as Hex,
// from: '0xEd123cf8e3bA51c6C15DA1eAc74B2b5DEEA31448',
// chainId: '137',
// nonce: 10
// },
// contractRegistry
// }
// const decoded = decode(input)
// const expected: TransferErc20 = {
// type: Intents.TRANSFER_ERC20,
// contract: 'eip155:137:0x031d8C0cA142921c459bCB28104c0FF37928F9eD' as Caip10,
// to: 'eip155:137:0xfe8f4de6e39c523ced231e7a72628f58e0ffee71' as Caip10,
// from: 'eip155:137:0xEd123cf8e3bA51c6C15DA1eAc74B2b5DEEA31448' as Caip10,
// amount: '500000000000000000000'
// }
// expect(decoded).toEqual(expected)
// })
})
})
})
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AbiParameter, Hex, decodeAbiParameters, toBytes } from 'viem'
import { AbiParameter, Hex, decodeAbiParameters } from 'viem'
import {
Erc20Methods,
Erc20TransferAbi,
Expand All @@ -19,7 +19,7 @@ export function decodeAbiParametersWrapper<TParams extends readonly AbiParameter
// re-doing a lot of the work that is already done in viem
export const extractErc20TransferAmount = (data: Hex): string => {
try {
const paramValues = decodeAbiParameters(Erc20TransferAbiParameters, toBytes(data))
const paramValues = decodeAbiParameters(Erc20TransferAbiParameters, data)

const amount = paramValues[1]
if (!amount) throw new Error('Malformed transaction request')
Expand Down
23 changes: 23 additions & 0 deletions packages/transaction-request-intent/src/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Hex } from 'viem'
import { InputType } from './lib/domain'
import { decode } from './lib/export'
import { Erc20Methods } from './lib/methodId'
import { TransactionInput } from './lib/types'

const input: TransactionInput = {
type: InputType.TRANSACTION_REQUEST,
txRequest: {
to: '0x031d8C0cA142921c459bCB28104c0FF37928F9eD',
data: `${Erc20Methods.TRANSFER}000000000000000000000000fe8f4de6e39c523ced231e7a72628f58e0ffee71000000000000000000000000000000000000000000000000000000000007a120` as Hex,
from: '0xEd123cf8e3bA51c6C15DA1eAc74B2b5DEEA31448',
chainId: '137',
nonce: 10
}
}

const main = () => {
const decoded = decode(input)
console.log(decoded)
}

main()
2 changes: 1 addition & 1 deletion packages/transaction-request-intent/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"declaration": true,
"types": []
"types": ["node"],
},
"include": ["src/**/*.ts"],
"exclude": ["jest.config.ts", "src/**/*.spec.ts"]
Expand Down

0 comments on commit 6a89f88

Please sign in to comment.