Skip to content

Commit

Permalink
Fix tests (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
samteb authored Feb 12, 2024
1 parent 45008d0 commit a947f5a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { AssetType, Hex, toAccountId, toAssetId } from '@narval/authz-shared'
import { AssetType, Hex, toAssetId } from '@narval/authz-shared'
import { Address } from 'viem'
import { ContractCallInput, Intents } from '../../../domain'
import { DecoderError } from '../../../error'
import { Erc1155SafeTransferFromParams, SafeBatchTransferFromParams } from '../../../extraction/types'
import { ERC1155Transfer, TransferErc1155 } from '../../../intent.types'
import { MethodsMapping, SupportedMethodId } from '../../../supported-methods'
import { isSupportedMethodId } from '../../../typeguards'
import { toAccountIdLowerCase } from '../../../utils'
import { extract } from '../../utils'

export const decodeERC1155Transfer = (input: ContractCallInput, supportedMethods: MethodsMapping): TransferErc1155 => {
Expand Down Expand Up @@ -71,10 +72,10 @@ function constructTransferErc1155Intent({
chainId: number
}): TransferErc1155 {
return {
to: toAccountId({ chainId, address: to }),
from: toAccountId({ chainId, address: from }),
to: toAccountIdLowerCase({ chainId, address: to }),
from: toAccountIdLowerCase({ chainId, address: from }),
type: Intents.TRANSFER_ERC1155,
transfers,
contract: toAccountId({ chainId, address: contract })
contract: toAccountIdLowerCase({ chainId, address: contract })
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Address } from '@narval/authz-shared'
import { assertAddress, assertBigInt, assertHexString } from 'packages/authz-shared/src/lib/util/typeguards'
import { assertAddress, assertHexString } from 'packages/authz-shared/src/lib/util/typeguards'
import { Hex, toHex } from 'viem'
import { ContractCallInput, InputType, Intents } from '../../../domain'
import { DecoderError } from '../../../error'
Expand All @@ -17,12 +17,12 @@ const decodeExecute = (callData: Hex, from: Address, chainId: number, supportedM
const params = extract(supportedMethods, dataWithoutMethodId, SupportedMethodId.EXECUTE) as ExecuteParams
const { to, value, data } = params

const assertAddressfrom = assertAddress(from)
const assertAddressTo = assertAddress(to)
const assertAddressfrom = assertAddress(from)
const assertAddressValue = assertHexString(value)
const assertData = assertHexString(data)

if (!assertAddressfrom || !assertAddressTo || !assertAddressValue || !assertData) {
if (!assertAddressTo || !assertAddressfrom || !assertAddressValue || !assertData) {
throw new DecoderError({ message: 'Invalid parameters', status: 400 })
}

Expand Down Expand Up @@ -56,29 +56,25 @@ const decodeExecuteAndRevert = (
dataWithoutMethodId,
SupportedMethodId.EXECUTE_AND_REVERT
) as ExecuteAndRevertParams
const { to, value } = params
const bigint = assertBigInt(value)

if (!bigint) {
throw new DecoderError({ message: 'Invalid value', status: 400 })
}
const { to, value, data } = params

const hexValue = toHex(bigint)
const assertAddressfrom = assertAddress(from)
const assertAddressTo = assertAddress(to)
const assertAddressfrom = assertAddress(from)
const assertValue = toHex(value)
const assertData = assertHexString(data)

if (!assertAddressfrom || !assertAddressTo) {
if (!assertAddressTo || !assertAddressfrom || !assertData) {
throw new DecoderError({ message: 'Invalid parameters', status: 400 })
}

return decode({
input: {
type: InputType.TRANSACTION_REQUEST,
txRequest: {
to: assertAddress(to),
to: assertAddressTo,
from: assertAddressfrom,
value: hexValue,
data: assertAddressTo,
value: assertValue,
data: assertData,
chainId
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ export const ExecuteParamsTransform = (params: unknown[]): ExecuteParams => {
const value = assertBigInt(params[1])
const data = assertHexString(params[2])

if (!to || !value || !data) {
// value can be 0 so we must be explicit that we check for non null value
if (!to || null === value || !data) {
throw new DecoderError({ message: 'Invalid parameters', status: 400 })
}

Expand Down Expand Up @@ -181,15 +182,15 @@ export const HandleOpsParamsTransform = (params: unknown[]): HandleOpsParams =>
throw new DecoderError({ message: 'Invalid input format', status: 400 })
}

const assertAddressBeneficiary = assertAddress(params[1])
const assertBeneficiary = assertAddress(params[1])

if (!assertAddressBeneficiary) {
if (!assertBeneficiary) {
throw new DecoderError({ message: 'Invalid parameters', status: 400 })
}

return {
userOps: params[0].map(transformUserOperation),
beneficiary: assertAddressBeneficiary
beneficiary: assertBeneficiary
}
}

Expand Down

0 comments on commit a947f5a

Please sign in to comment.