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

adds ironfish-tank simulation to test encrypted wallet migrations #79

Draft
wants to merge 1 commit into
base: feat/hughy/node-run-cmd
Choose a base branch
from
Draft
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
5 changes: 4 additions & 1 deletion fishtank/src/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@ export class Cluster {
async spawn(options: {
name: string
image?: string
command?: string
config?: Partial<ConfigOptions>
internal?: Partial<InternalOptions>
networkDefinition?: Partial<NetworkDefinition>
extraArgs?: string[]
waitForStart?: boolean
}): Promise<Node> {
const config = options.config || {}
Expand All @@ -103,6 +105,7 @@ export class Cluster {
private async internalSpawn(options: {
name: string
image?: string
command?: string
config?: Partial<ConfigOptions>
internal?: Partial<InternalOptions>
networkId?: number
Expand All @@ -116,7 +119,7 @@ export class Cluster {
const containerName = naming.containerName(this, options.name)

const runOptions = {
args: ['start'],
args: [options.command ?? 'start'],
name: containerName,
networks: [naming.networkName(this)],
hostname: options.name,
Expand Down
75 changes: 75 additions & 0 deletions scenarios/src/migrateEncryptedWallet.simulation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import { Cluster } from 'fishtank'
import { withTestCluster } from '.'

describe('migrations on encrypted wallets', () => {
it('should run successfully', async () => {
return withTestCluster(async (cluster: Cluster) => {
await cluster.init()

// start node on latest version before encrypted wallet migrations
let node1 = await cluster.spawn({
name: 'node-1',
image: 'ghcr.io/iron-fish/ironfish:v2.6.0',
})

let node1Rpc = await node1.connectRpc()

// mine blocks to establish nonzero balance
await node1.mineUntil({ accountBalance: 1n })

const node1BalanceBefore = (
await node1Rpc.wallet.getAccountBalance({ account: 'default' })
).content.unconfirmed

// verify that wallet is NOT locked
const unlockedStatus = await node1Rpc.wallet.getAccountsStatus()
expect(unlockedStatus.content.locked).toBe(false)

// encrypt wallet
const passphrase = 'encrypted-wallet'
await node1Rpc.wallet.encrypt({ passphrase })

// verify that wallet is locked
const lockedStatus = await node1Rpc.wallet.getAccountsStatus()
expect(lockedStatus.content.locked).toBe(true)

// stop node
await node1.remove()

// TODO: replace branch image with default image after release of first
// encrypted wallet migration
const migrationImage =
'546281846244.dkr.ecr.us-east-1.amazonaws.com/ironfish:migrate-encrypted-wallet'

// run migrations on latest image and include the wallet passphrase
const migrations = await node1.runCommand({
baseName: 'migrations',
image: migrationImage,
args: ['migrations:start', '--passphrase', passphrase],
})
expect(migrations.stdout).not.toContain('Cannot run migration on encrypted wallet')
expect(migrations.stdout).toContain('Successfully applied')

// start node on latest image to verify that node starts successfully
node1 = await cluster.spawn({
name: 'node-1',
image: migrationImage,
})

node1Rpc = await node1.connectRpc()

// unlock wallet
await node1Rpc.wallet.unlock({ passphrase })

// verify that balance is unchanged after migrations
const node1BalanceAfter = (
await node1Rpc.wallet.getAccountBalance({ account: 'default' })
).content.unconfirmed

expect(node1BalanceAfter).toEqual(node1BalanceBefore)
})
})
})
Loading