Skip to content

Commit

Permalink
end to end working tests for transactions inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ptroger committed Jan 19, 2024
1 parent db2b95d commit c7b8899
Show file tree
Hide file tree
Showing 9 changed files with 974 additions and 307 deletions.

Large diffs are not rendered by default.

190 changes: 106 additions & 84 deletions packages/transaction-request-intent/src/lib/__test__/unit/mocks.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { TransactionRequest } from '@narval/authz-shared'
import { Address } from 'viem'
import { Caip10, Caip19 } from '../../caip'
import { Intents } from '../../domain'
import { TransferNative } from '../../intent.types'
import { InputType, Intents } from '../../domain'
import { TransferErc1155, TransferErc20, TransferErc721, TransferNative } from '../../intent.types'
import { TransactionInput } from '../../types'

export const ONE_ETH = BigInt('1000000000000000000')

Expand Down Expand Up @@ -243,10 +244,10 @@ export const NATIVE_TRANSFER_INTENT: TransferNative = {
to: 'eip155:137/eoa:0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4' as Caip10,
from: 'eip155:137/eoa:0x90d03a8971a2faa19a9d7ffdcbca28fe826a289b' as Caip10,
amount: '0x8000',
token: 'eip155:1/slip44:60' as Caip19 // Caip19 for ETH
token: 'eip155:1/slip44/60' as Caip19 // Caip19 for ETH
}

export const ERC20_TRANSFER_TX_REQUEST: TransactionRequest = {
const ERC20_TRANSFER_TX_REQUEST: TransactionRequest = {
from: TREASURY_WALLET_X.address as Address,
to: '0x031d8C0cA142921c459bCB28104c0FF37928F9eD' as Address,
chainId: ACCOUNT_Q_137.chainId,
Expand All @@ -255,102 +256,123 @@ export const ERC20_TRANSFER_TX_REQUEST: TransactionRequest = {
type: '2'
}

export const NATIVE_TRANSFER_TX_REQUEST: TransactionRequest = {
const ERC20_TRANSFER_INTENT: TransferErc20 = {
type: Intents.TRANSFER_ERC20,
to: `eip155:137:0x031d8c0ca142921c459bcb28104c0ff37928f9ed` as Caip10,
from: `eip155:137:${ERC20_TRANSFER_TX_REQUEST.from.toLowerCase()}` as Caip10,
contract: `eip155:137:${ERC20_TRANSFER_TX_REQUEST.to?.toLowerCase()}` as Caip10,
amount: '428406414311469998210669'
}

const ERC721_SAFE_TRANSFER_FROM_TX_REQUEST: TransactionRequest = {
from: TREASURY_WALLET_X.address as Address,
to: ACCOUNT_Q_137.address as Address,
chainId: ACCOUNT_Q_137.chainId,
value: '0x8000',
data: '0x',
data: '0x42842e0e000000000000000000000000ea7278a0d8306658dd6d38274dde084f24cd8a11000000000000000000000000b253f6156e64b12ba0dec3974062dbbaee139f0c000000000000000000000000000000000000000000000000000000000000a0d5',
nonce: 192,
type: '2'
}

export const REGO_REQUEST = {
action: Action.SIGN_TRANSACTION,
request: NATIVE_TRANSFER_TX_REQUEST,
intent: NATIVE_TRANSFER_INTENT,
resource: {
uid: TREASURY_WALLET_X.uid
},
principal: {
uid: MATT.uid
},
signatures: []
const ERC721_SAFE_TRANSFER_FROM_INTENT: TransferErc721 = {
type: Intents.TRANSFER_ERC721,
to: `eip155:137:0xb253f6156e64b12ba0dec3974062dbbaee139f0c` as Caip10,
from: `eip155:137:${ERC721_SAFE_TRANSFER_FROM_TX_REQUEST.from.toLowerCase()}` as Caip10,
contract: `eip155:137:${ERC721_SAFE_TRANSFER_FROM_TX_REQUEST.to?.toLowerCase()}` as Caip10,
nftId: `eip155:137/erc721:${ERC721_SAFE_TRANSFER_FROM_TX_REQUEST.to}/41173` as Caip19
}

export const mockErc721SafeTransferFrom = {
input: {
type: InputType.TRANSACTION_REQUEST,
txRequest: ERC721_SAFE_TRANSFER_FROM_TX_REQUEST
} as TransactionInput,
intent: ERC721_SAFE_TRANSFER_FROM_INTENT
}

// Role Permissions
// Of course we can have different permissions per resource, but for now we'll just use the same permissions for all resources.
const transferFromData =
'0x23b872dd000000000000000000000000ce5550ac05e0c6ab27418de56fc57c852de961d400000000000000000000000059895c2cdaa07cc3ac20ef0918d2597a277b276c000000000000000000000000000000000000000000000000000000000000159c'

export const ROOT_PERMISSIONS: RolePermission = {
permit: true
export const mockTransferFrom = {
input: {
type: InputType.TRANSACTION_REQUEST,
txRequest: {
from: TREASURY_WALLET_X.address as Address,
to: ACCOUNT_Q_137.address as Address,
chainId: ACCOUNT_Q_137.chainId,
data: transferFromData,
nonce: 192,
type: '2'
}
} as TransactionInput,
intent: {
to: `eip155:137:0x59895c2cdaa07cc3ac20ef0918d2597a277b276c` as Caip10,
from: `eip155:137:${TREASURY_WALLET_X.address}` as Caip10,
contract: `eip155:137:${ACCOUNT_Q_137.address}` as Caip10,
amount: '5532'
}
}

export const ADMIN_PERMISSIONS: RolePermission = {
permit: true,
admin_quorum_threshold: 1
const ERC1155_SAFE_TRANSFER_FROM_TX_REQUEST: TransactionRequest = {
from: TREASURY_WALLET_X.address as Address,
to: ACCOUNT_Q_137.address as Address,
chainId: ACCOUNT_Q_137.chainId,
data: '0xf242432a000000000000000000000000d15b4cb5495cffa8d01970018ea3bc4942e34b7a00000000000000000000000000ca04c45da318d5b7e7b14d5381ca59f09c73f000000000000000000000000000000000000000000000000000000000000000af000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000704760f2a0b00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000ca04c45da318d5b7e7b14d5381ca59f09c73f00000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006042b8a88ec00000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000005c0000000000000000000000000d15b4cb5495cffa8d01970018ea3bc4942e34b7a000000000000000000000000d15b4cb5495cffa8d01970018ea3bc4942e34b7a000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000005e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000046000000000000000000000000000000000000000000000000000000000000004e0000000000000000000000000cb02f88ea1b95ba4adccfc0d0ac2a6052b70f2e400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000065a9d6a20000000000000000000000000000000000000000000000000000000065adcb5d000000000000000000000000000000000000000000000000000000000000000060665ba51d4da48b00000000000000004cb15528fa439a0e4e2a583202e926d50000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f00000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000d500b1d8e8ef31e21c99d1db9a6444d3adf127000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024b2b50d4fec700000000000000000000000000000000000000000000000000024b2b50d4fec7000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003000000000000000000000000939821fd096b4e4f67f369af67cf9411b1a2816000000000000000000000000000000000000000000000000000000000000000af00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000cb02f88ea1b95ba4adccfc0d0ac2a6052b70f2e400000000000000000000000000000000000000000000000000000000000000010000000000000000000000000d500b1d8e8ef31e21c99d1db9a6444d3adf127000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001d5bc40aa656c0000000000000000000000000000000000000000000000000001d5bc40aa656c00000000000000000000000000001f429aa3c402e9deabe8a8ecae7d37b0d35452c0000000000000000000000000000000000000000000000000000000000000041efa2557bc958943cb6a7df19ae9c8b1b516515b5184f21516458a44d559141d94229134f3da4243b36151bba8cc65bf4d441a277326a87e59b1b5dcb18c681021b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001d4da48b60665ba5',
nonce: 192,
type: '2'
}

export const MANAGER_PERMISSIONS: RolePermission = {
permit: true,
admin_quorum_threshold: 2
const ERC1155_SAFE_TRANSFER_FROM_INTENT: TransferErc1155 = {
type: Intents.TRANSFER_ERC1155,
to: `eip155:137:0x00ca04c45da318d5b7e7b14d5381ca59f09c73f0` as Caip10,
from: `eip155:137:${ERC1155_SAFE_TRANSFER_FROM_TX_REQUEST.from.toLowerCase()}` as Caip10,
contract: `eip155:137:${ERC1155_SAFE_TRANSFER_FROM_TX_REQUEST.to?.toLowerCase()}` as Caip10,
transfers: [{ tokenId: `eip155:137/erc1155:${ERC1155_SAFE_TRANSFER_FROM_TX_REQUEST.to}/175` as Caip19, amount: '1' }]
}
export const mockErc1155SafeTransferFrom = {
input: {
type: InputType.TRANSACTION_REQUEST,
txRequest: ERC1155_SAFE_TRANSFER_FROM_TX_REQUEST
} as TransactionInput,
intent: ERC1155_SAFE_TRANSFER_FROM_INTENT
}

export const mockEntityData: RegoData = {
entities: {
users: {
[ROOT_USER.uid]: ROOT_USER,
[MATT.uid]: MATT,
[AAUser.uid]: AAUser,
[BBUser.uid]: BBUser
},
user_groups: {
[DEV_USER_GROUP.uid]: DEV_USER_GROUP,
[TREASURY_USER_GROUP.uid]: TREASURY_USER_GROUP
},
wallets: {
[SHY_ACCOUNT_WALLET.uid]: SHY_ACCOUNT_WALLET,
[PIERRE_WALLET.uid]: PIERRE_WALLET,
[WALLET_Q.uid]: WALLET_Q,
[TREASURY_WALLET_X.uid]: TREASURY_WALLET_X
},
wallet_groups: {
[DEV_WALLET_GROUP.uid]: DEV_WALLET_GROUP,
[TREASURY_WALLET_GROUP.uid]: TREASURY_WALLET_GROUP
},
address_book: {
[SHY_ACCOUNT_137.uid]: SHY_ACCOUNT_137,
[SHY_ACCOUNT_1.uid]: SHY_ACCOUNT_1,
[ACCOUNT_INTERNAL_WXZ_137.uid]: ACCOUNT_INTERNAL_WXZ_137,
[ACCOUNT_Q_137.uid]: ACCOUNT_Q_137
}
},
permissions: {
[Action.CREATE_USER]: {
[UserRoles.ROOT]: ROOT_PERMISSIONS,
[UserRoles.ADMIN]: ADMIN_PERMISSIONS
},
[Action.EDIT_USER]: {
[UserRoles.ROOT]: ROOT_PERMISSIONS,
[UserRoles.ADMIN]: ADMIN_PERMISSIONS
},
[Action.DELETE_USER]: {
[UserRoles.ROOT]: ROOT_PERMISSIONS,
[UserRoles.ADMIN]: ADMIN_PERMISSIONS
},
[Action.CREATE_WALLET]: {
[UserRoles.ROOT]: ROOT_PERMISSIONS
},
[Action.EDIT_WALLET]: {
[UserRoles.ROOT]: ROOT_PERMISSIONS,
[UserRoles.MANAGER]: MANAGER_PERMISSIONS
},
[Action.ASSIGN_WALLET]: {
[UserRoles.ROOT]: ROOT_PERMISSIONS,
[UserRoles.MANAGER]: MANAGER_PERMISSIONS
const ERC1155_BATCH_SAFE_TRANSFER_FROM_REQUEST = {
from: TREASURY_WALLET_X.address as Address,
to: ACCOUNT_Q_137.address as Address,
chainId: ACCOUNT_Q_137.chainId,
data: '0x2eb2c2d60000000000000000000000008b149b00ce4ad98878ec342d69eb42dcbcbd6306000000000000000000000000383370726a5bd619e0d2af8ef37a58013b823a8c00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000b9c00000000000000000000000000000000000000000000000000000000000000a200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000610000000000000000000000000000000000000000000000000000000065a9d9340feb2529261db182817eef5823d8f659495e6bdc097b95cac8011dd73a13be723d4c281943fbfff8b8ba89cfa2a44286411e94e8eb9601502914ffd41764bc781c00000000000000000000000000000000000000000000000000000000000000',
nonce: 2
}

const ERC1155_BATCH_SAFE_TRANSFER_FROM_INTENT = {
type: Intents.TRANSFER_ERC1155,
from: `eip155:137:${ERC1155_BATCH_SAFE_TRANSFER_FROM_REQUEST.from.toLowerCase()}` as Caip10,
to: `eip155:137:0x383370726a5bd619e0d2af8ef37a58013b823a8c` as Caip10,
contract: `eip155:137:${ERC1155_BATCH_SAFE_TRANSFER_FROM_REQUEST.to?.toLowerCase()}` as Caip10,
transfers: [
{
tokenId: `eip155:137/erc1155:${ERC1155_BATCH_SAFE_TRANSFER_FROM_REQUEST.to}/2972` as Caip19,
amount: '1'
},
[Action.UNASSIGN_WALLET]: {
[UserRoles.ROOT]: ROOT_PERMISSIONS,
[UserRoles.MANAGER]: MANAGER_PERMISSIONS
{
tokenId: `eip155:137/erc1155:${ERC1155_BATCH_SAFE_TRANSFER_FROM_REQUEST.to}/162` as Caip19,
amount: '1'
}
}
]
}

export const mockErc1155BatchSafeTransferFrom = {
input: {
type: InputType.TRANSACTION_REQUEST,
txRequest: ERC1155_BATCH_SAFE_TRANSFER_FROM_REQUEST
} as TransactionInput,
intent: ERC1155_BATCH_SAFE_TRANSFER_FROM_INTENT
}

export const mockErc20Transfer = {
input: {
type: InputType.TRANSACTION_REQUEST,
txRequest: ERC20_TRANSFER_TX_REQUEST
} as TransactionInput,
intent: ERC20_TRANSFER_INTENT
}

This file was deleted.

Loading

0 comments on commit c7b8899

Please sign in to comment.