Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh committed Dec 12, 2024
1 parent 00d4b9d commit dfe445a
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions src/utils/__tests__/safe-migrations.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ImplementationVersionState } from '@safe-global/safe-gateway-typescript-sdk'
import { type ChainInfo, ImplementationVersionState } from '@safe-global/safe-gateway-typescript-sdk'
import { OperationType } from '@safe-global/safe-core-sdk-types'
import { extractMigrationL2MasterCopyAddress, prependSafeToL2Migration } from '../safe-migrations'
import { extendedSafeInfoBuilder } from '@/tests/builders/safe'
import { chainBuilder } from '@/tests/builders/chains'
Expand All @@ -9,14 +10,16 @@ import {
getSafeL2SingletonDeployment,
getSafeSingletonDeployment,
getSafeToL2MigrationDeployment,
getSafeMigrationDeployment,
} from '@safe-global/safe-deployments'
import type Safe from '@safe-global/protocol-kit'
import { encodeMultiSendData } from '@safe-global/protocol-kit'
import { Multi_send__factory, Safe_to_l2_migration__factory } from '@/types/contracts'
import { Multi_send__factory, Safe_to_l2_migration__factory, Safe_migration__factory } from '@/types/contracts'
import { faker } from '@faker-js/faker'
import { getAndValidateSafeSDK } from '@/services/tx/tx-sender/sdk'
import { decodeMultiSendData } from '@safe-global/protocol-kit/dist/src/utils'
import { checksumAddress } from '../addresses'
import { createUpdateMigration } from '../safe-migrations'

jest.mock('@/services/tx/tx-sender/sdk')

Expand Down Expand Up @@ -318,4 +321,45 @@ describe('extractMigrationL2MasterCopyAddress', () => {
),
).toEqual(l2SingletonAddress)
})

describe('createUpdateMigration', () => {
const mockChain = {
chainId: '1',
l2: false,
recommendedMasterCopyVersion: '1.4.1',
} as unknown as ChainInfo

const mockChainOld = {
chainId: '1',
l2: false,
recommendedMasterCopyVersion: '1.3.0',
} as unknown as ChainInfo

it('should create a migration transaction for L1 chain', () => {
const result = createUpdateMigration(mockChain)

expect(result).toEqual({
operation: OperationType.DelegateCall,
data: '0xed007fc6',
to: '0x526643F69b81B008F46d95CD5ced5eC0edFFDaC6',
value: '0',
})
})

it('should create a migration transaction for L2 chain', () => {
const l2Chain = { ...mockChain, l2: true }
const result = createUpdateMigration(l2Chain)

expect(result).toEqual({
operation: OperationType.DelegateCall,
data: '0x68cb3d94',
to: '0x526643F69b81B008F46d95CD5ced5eC0edFFDaC6',
value: '0',
})
})

it('should throw an error if deployment is not found', () => {
expect(() => createUpdateMigration(mockChainOld)).toThrow('Migration deployment not found')
})
})
})

0 comments on commit dfe445a

Please sign in to comment.