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

Fix/update tests #2

Merged
merged 5 commits into from
Mar 26, 2024
Merged
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
10 changes: 5 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
PK=

# Test Variables
VITE_TEST_NETWORK_TYPE='ETHEREUM_GOERLI'
VITE_EXAMPLE_SAFE='SHORTNAME:ADDRESS'
VITE_TEST_ADDRESS=
VITE_ANVIL_FORK_URL=
VITE_ANVIL_BLOCK_NUMBER=
VITE_TEST_NETWORK_TYPE='ETHEREUM_SEPOLIA'
VITE_EXAMPLE_SAFE='SHORTNAME:ADDRESS' # sep:0xbcA814Ee6E571d0BbC335b4e3869F89E532Ba8B8
VITE_TEST_ADDRESS= # sep:0xD7a0ca30F71cFDF45534B058c567a5FaE6C33846
VITE_ANVIL_FORK_URL=https://eth-sepolia.g.alchemy.com/v2/[KEY]
VITE_ANVIL_BLOCK_NUMBER=5211612
3 changes: 2 additions & 1 deletion src/actions/public/getSafeOwners.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { getSafeOwners } from './getSafeOwners.js'
import { publicClient } from '../../../tests/utils.js'
import { EIP3770Address } from '../../types.js'
import { EXAMPLE_SAFE, TEST_ADDRESS } from '../../../tests/constants.js'
import { parseEip3770Address } from '../../utils/eip-3770.js'

describe('getSafeOwners', () => {
it('should retrieve the safes owners', () => {
getSafeOwners(publicClient, EXAMPLE_SAFE as EIP3770Address).then((owners) => {
expect(owners).includes(TEST_ADDRESS)
expect(owners).includes(parseEip3770Address(TEST_ADDRESS).address)
})
})
})
28 changes: 13 additions & 15 deletions src/api.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { describe, it, expect } from 'vitest'
import { ApiClient } from './api.js'
import { goerli, sepolia } from 'viem/chains'
import { TEST_ADDRESS, EXAMPLE_SAFE_ADDRESS, EXAMPLE_SAFE, MULTISIG_TRANSACTION_TEST_RESPONSE, EXAMPLE_SAFE_INFO_RESPONSE } from '../tests/constants.js'
import { sepolia, goerli } from 'viem/chains'
import { TEST_ADDRESS, EXAMPLE_SAFE_ADDRESS, EXAMPLE_SAFE } from '../tests/constants.js'
import { EXAMPLE_SAFE_INFO_RESPONSE, MULTISIG_TRANSACTION_TEST_RESPONSE_0, MULTISIG_TRANSACTION_TEST_RESPONSE_1, NONCE_0, TEST_TRANSACTION_HASH_0 } from '../tests/test-data.js'

describe('ApiClient', () => {
it('initializes properly', () => {
Expand All @@ -14,7 +15,6 @@ describe('ApiClient', () => {
describe('getSafeInfo', () => {
it('should return the safe info', async () => {
const api = new ApiClient({ url: 'https://safe-transaction-sepolia.safe.global', chainId: sepolia.id, safeAddress: EXAMPLE_SAFE })

const result = await api.getSafeInfo(EXAMPLE_SAFE)

expect(result).toEqual(EXAMPLE_SAFE_INFO_RESPONSE)
Expand All @@ -24,20 +24,19 @@ describe('ApiClient', () => {
describe('getTransaction', () => {
it('should return a transaction for a given tx hash', async () => {
const api = new ApiClient({ url: 'https://safe-transaction-sepolia.safe.global', chainId: sepolia.id, safeAddress: EXAMPLE_SAFE })
const result = await api.getTransaction(TEST_TRANSACTION_HASH_0)

const result = await api.getTransaction('0x8759267d96af12fbee209a50a5a12a993fdbd81cd8692893a24de5e82fdb52a7')

expect(result).toEqual(MULTISIG_TRANSACTION_TEST_RESPONSE)
expect(result).toEqual(MULTISIG_TRANSACTION_TEST_RESPONSE_0)
})
})

describe('getMultisigTransactions', () => {
it('should return a list of transactions for a given safe address', async () => {
const api = new ApiClient({ url: 'https://safe-transaction-sepolia.safe.global', chainId: sepolia.id, safeAddress: EXAMPLE_SAFE })

const result = await api.getMultisigTransactions(EXAMPLE_SAFE)

expect(result.results[0]).toEqual(MULTISIG_TRANSACTION_TEST_RESPONSE)
const firstTx = result?.results.find((tx) => tx.nonce == NONCE_0)
expect(firstTx).toEqual(MULTISIG_TRANSACTION_TEST_RESPONSE_0)
})
})

Expand All @@ -49,20 +48,19 @@ describe('ApiClient', () => {

expect(result).toEqual(
{
count: 0,
count: 1,
next: null,
previous: null,
results: [],
countUniqueNonce: 1
results: [MULTISIG_TRANSACTION_TEST_RESPONSE_1],
countUniqueNonce: 2
})
})
})

describe('getDelegates', () => {
// TODO convert to sepolia safe
describe.skip('getDelegates', () => {
it('should list all delegates', async () => {
const EXAMPLE_SAFE = 'gor:0x04786B39Bd84b3a5344dC7355e4d8785b0981902'

const api = new ApiClient({ url: 'https://safe-transaction-goerli.safe.global', chainId: goerli.id, safeAddress: EXAMPLE_SAFE })
const api = new ApiClient({ url: 'https://safe-transaction-goerli.safe.global', chainId: goerli.id, safeAddress: 'gor:0x04786B39Bd84b3a5344dC7355e4d8785b0981902' })

const result = await api.getDelegates()

Expand Down
42 changes: 21 additions & 21 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@ export type SafeTransactionData = {
}

export type SafeInfoResponse = {
readonly address: string
readonly nonce: number
readonly threshold: number
readonly owners: string[]
readonly masterCopy: string
readonly modules: string[]
readonly fallbackHandler: string
readonly guard: string
readonly address: Address
readonly nonce: string
readonly threshold: string
readonly owners: Address[]
readonly masterCopy: Address
readonly modules: Address[]
readonly fallbackHandler: Address
readonly guard: Address
readonly version: string
}

export type SafeMultisigConfirmationResponse = {
readonly owner: string
readonly owner: Address
readonly submissionDate: string
readonly transactionHash?: string
readonly transactionHash?: Hex
readonly confirmationType?: string
readonly signature: string
readonly signature: Hex
readonly signatureType?: string
}

Expand All @@ -60,25 +60,25 @@ export type SafeMultisigConfirmationListResponse = {
}

export type SafeMultisigTransactionResponse = {
readonly safe: string
readonly to: string
readonly safe: Address
readonly to: Address
readonly value: string
readonly data?: string
readonly data?: Hex
readonly operation: number
readonly gasToken: string
readonly safeTxGas: number
readonly baseGas: number
readonly gasPrice: string
readonly refundReceiver?: string
readonly refundReceiver?: Address
readonly nonce: number
readonly executionDate: string
readonly submissionDate: string
readonly modified: string
readonly blockNumber?: number
readonly transactionHash: string
readonly safeTxHash: string
readonly proposer: string // ! safe-core-sdk-types file does not include this, but api returns it
readonly executor?: string
readonly transactionHash: Hex
readonly safeTxHash: Hex
readonly proposer: Address // ! safe-core-sdk-types file does not include this, but api returns it
readonly executor?: Address
readonly isExecuted: boolean
readonly isSuccessful?: boolean
readonly ethGasPrice?: string
Expand All @@ -91,7 +91,7 @@ export type SafeMultisigTransactionResponse = {
readonly confirmationsRequired: number
readonly confirmations?: SafeMultisigConfirmationResponse[]
readonly trusted: boolean
readonly signatures?: string
readonly signatures?: Hex
}

export type SafeMultisigTransactionListResponse = {
Expand All @@ -103,5 +103,5 @@ export type SafeMultisigTransactionListResponse = {
}

export type SignatureResponse = {
readonly signature: string
readonly signature: Hex
}
65 changes: 1 addition & 64 deletions tests/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Address } from "viem"
import { NetworkType } from "../src/utils/networks.js"
import { EIP3770Address, SafeInfoResponse, SafeMultisigTransactionResponse } from "../src/types.js"
import { EIP3770Address } from "../src/types.js"

// ========================================
// TEST ACCOUNT VARIABLES
Expand Down Expand Up @@ -49,66 +49,3 @@ if (!process.env.VITE_ANVIL_BLOCK_NUMBER) {
export const FORK_BLOCK_NUMBER = BigInt(
Number(process.env.VITE_ANVIL_BLOCK_NUMBER),
)

// ========================================
// TEST TRANSACTION DATA
// ========================================

// Example safe:
export const EXAMPLE_SAFE_INFO_RESPONSE: SafeInfoResponse = {
address: "0x156c02168925748D29132Ae680f76E3A9e20EEe0",
nonce: 1,
threshold: 1,
owners: [
"0xD7a0ca30F71cFDF45534B058c567a5FaE6C33846"
],
masterCopy: "0xfb1bffC9d739B8D520DaF37dF666da4C687191EA",
modules: [],
fallbackHandler: "0x017062a1dE2FE6b99BE3d9d37841FeD19F573804",
guard: "0x0000000000000000000000000000000000000000",
version: "1.3.0+L2"
}

// Example transaction: https://sepolia.etherscan.io/tx/0xdade8c7d02460289c76e05f2888e797d21dda4404cb867c988cc0a0e22ff7f60
export const MULTISIG_TRANSACTION_TEST_RESPONSE: SafeMultisigTransactionResponse = {
safe: "0x156c02168925748D29132Ae680f76E3A9e20EEe0",
to: "0xD7a0ca30F71cFDF45534B058c567a5FaE6C33846",
value: "10000000000000000",
data: null,
operation: 0,
gasToken: "0x0000000000000000000000000000000000000000",
safeTxGas: 0,
baseGas: 0,
gasPrice: "0",
refundReceiver: "0x0000000000000000000000000000000000000000",
nonce: 0,
executionDate: "2023-11-10T09:21:48Z",
submissionDate: "2023-11-10T09:21:05.933593Z",
modified: "2023-11-10T09:21:48Z",
blockNumber: 4665386,
transactionHash: "0xdade8c7d02460289c76e05f2888e797d21dda4404cb867c988cc0a0e22ff7f60",
safeTxHash: "0x8759267d96af12fbee209a50a5a12a993fdbd81cd8692893a24de5e82fdb52a7",
proposer: "0xD7a0ca30F71cFDF45534B058c567a5FaE6C33846",
executor: "0xD7a0ca30F71cFDF45534B058c567a5FaE6C33846",
isExecuted: true,
isSuccessful: true,
ethGasPrice: "529597",
maxFeePerGas: "529597",
maxPriorityFeePerGas: "529597",
gasUsed: 77013,
fee: "40785853761",
origin: "{}",
dataDecoded: null,
confirmationsRequired: 1,
confirmations: [
{
owner: "0xD7a0ca30F71cFDF45534B058c567a5FaE6C33846",
submissionDate: "2023-11-10T09:21:48Z",
transactionHash: null,
signature: "0x000000000000000000000000d7a0ca30f71cfdf45534b058c567a5fae6c33846000000000000000000000000000000000000000000000000000000000000000001",
signatureType: "APPROVED_HASH"
}
],
trusted: true,
signatures: "0x000000000000000000000000d7a0ca30f71cfdf45534b058c567a5fae6c33846000000000000000000000000000000000000000000000000000000000000000001"
}
108 changes: 108 additions & 0 deletions tests/test-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import { SafeInfoResponse, SafeMultisigTransactionResponse } from "../src/types.js"

// ========================================
// TEST TRANSACTION DATA
// ========================================

// Example safe:
export const EXAMPLE_SAFE_INFO_RESPONSE: SafeInfoResponse = {
address: '0xbcA814Ee6E571d0BbC335b4e3869F89E532Ba8B8',
nonce: 1,
threshold: 1,
owners: ['0xD7a0ca30F71cFDF45534B058c567a5FaE6C33846'],
masterCopy: '0xfb1bffC9d739B8D520DaF37dF666da4C687191EA',
modules: [],
fallbackHandler: '0x017062a1dE2FE6b99BE3d9d37841FeD19F573804',
guard: '0x0000000000000000000000000000000000000000',
version: '1.3.0+L2'
}

export const NONCE_0 = 0
export const NONCE_1 = 1

// For nonce = 0
export const TEST_TRANSACTION_HASH_0 = '0xff325d5c14219e7fcf23ccec94d504384404adbfcfef0c846600876a6ef2d832';

export const MULTISIG_TRANSACTION_TEST_RESPONSE_0: SafeMultisigTransactionResponse = {
safe: '0xbcA814Ee6E571d0BbC335b4e3869F89E532Ba8B8',
to: '0xD7a0ca30F71cFDF45534B058c567a5FaE6C33846',
value: '10000000000000000',
data: null,
operation: 0,
gasToken: '0x0000000000000000000000000000000000000000',
safeTxGas: 0,
baseGas: 0,
gasPrice: '0',
refundReceiver: '0x0000000000000000000000000000000000000000',
nonce: 0,
executionDate: '2024-02-03T15:42:36Z',
submissionDate: '2024-02-03T15:26:43.618302Z',
modified: '2024-02-03T15:42:43.868176Z',
blockNumber: 5211894,
transactionHash: '0x6923496a7193d27e527d6b365ea65786e83bc1452c75e302e6f2c6563526ce7e',
safeTxHash: '0xff325d5c14219e7fcf23ccec94d504384404adbfcfef0c846600876a6ef2d832',
proposer: '0xD7a0ca30F71cFDF45534B058c567a5FaE6C33846',
executor: '0xD7a0ca30F71cFDF45534B058c567a5FaE6C33846',
isExecuted: true,
isSuccessful: true,
ethGasPrice: '5284136118',
maxFeePerGas: '9994182118',
maxPriorityFeePerGas: '100000',
gasUsed: 80822,
fee: '427074449328996',
origin: '{}',
dataDecoded: null,
confirmationsRequired: 1,
confirmations: [
{
owner: '0xD7a0ca30F71cFDF45534B058c567a5FaE6C33846',
submissionDate: '2024-02-03T15:26:43.684875Z',
transactionHash: null,
signature: '0x1cf589758060307d1a6209ff2239bacb1933231bbb7d1b97909049f4e818a26322aa1ab19291ba78685bd798a1438ccdf4da63def4cd2bf0ef02e92fd7fa8afa1b',
signatureType: 'EOA'
}
],
trusted: true,
signatures: '0x1cf589758060307d1a6209ff2239bacb1933231bbb7d1b97909049f4e818a26322aa1ab19291ba78685bd798a1438ccdf4da63def4cd2bf0ef02e92fd7fa8afa1b'
}

export const MULTISIG_TRANSACTION_TEST_RESPONSE_1: SafeMultisigTransactionResponse = {
safe: '0xbcA814Ee6E571d0BbC335b4e3869F89E532Ba8B8',
to: '0xD7a0ca30F71cFDF45534B058c567a5FaE6C33846',
value: '20000000000000000',
data: null,
operation: 0,
gasToken: '0x0000000000000000000000000000000000000000',
safeTxGas: 0,
baseGas: 0,
gasPrice: '0',
refundReceiver: '0x0000000000000000000000000000000000000000',
nonce: 1,
executionDate: null,
submissionDate: '2024-02-03T16:54:00.907184Z',
modified: '2024-02-03T16:54:00.990665Z',
blockNumber: null,
transactionHash: null,
safeTxHash: '0xb199f858df683d77591642442e02610bb81b5a418acef3237095be495b7988ae',
proposer: '0xD7a0ca30F71cFDF45534B058c567a5FaE6C33846',
executor: null,
isExecuted: false,
isSuccessful: null,
ethGasPrice: null,
maxFeePerGas: null,
maxPriorityFeePerGas: null,
gasUsed: null,
fee: null,
origin: '{}',
dataDecoded: null,
confirmationsRequired: 1,
confirmations: [{
owner: '0xD7a0ca30F71cFDF45534B058c567a5FaE6C33846',
submissionDate: '2024-02-03T16:54:00.990665Z',
transactionHash: null,
signature: '0x54d3e09114ef529192072b296bb5d254f05dbcba2bb54bd2fee7bf3901a74ab9746b0e1134d10fa435a87015a124ca918c8cf16838c1303e98d06462e0bdb7b01b',
signatureType: 'EOA'
}],
trusted: true,
signatures: null
}