diff --git a/__tests__/integration/core-api/handlers/peers.test.ts b/__tests__/integration/core-api/handlers/peers.test.ts index 57d4e785ce..1cc115b480 100644 --- a/__tests__/integration/core-api/handlers/peers.test.ts +++ b/__tests__/integration/core-api/handlers/peers.test.ts @@ -35,8 +35,7 @@ beforeAll(async () => { api = new ApiHelpers(app); const peerMocks = peers.map(mock => { - const peerMock = new Peer(app, mock.ip); - peerMock.port = mock.port; + const peerMock = new Peer(mock.ip, mock.port); peerMock.version = mock.version; peerMock.latency = mock.latency; peerMock.state.height = mock.state.height; diff --git a/__tests__/unit/core-test-framework/factories/factories/wallet.test.ts b/__tests__/unit/core-test-framework/factories/factories/wallet.test.ts index 305f85bb1d..88649222a3 100644 --- a/__tests__/unit/core-test-framework/factories/factories/wallet.test.ts +++ b/__tests__/unit/core-test-framework/factories/factories/wallet.test.ts @@ -1,16 +1,8 @@ import "jest-extended"; +import { Wallets } from "@arkecosystem/core-state"; import { FactoryBuilder, Factories } from "@packages/core-test-framework/src/factories"; -interface Wallet { - address: string; - publicKey: string; - privateKey: string; - wif: string; - passphrase: string; - secondPassphrase?: string; -} - let factory: FactoryBuilder; beforeEach(() => { @@ -20,36 +12,23 @@ beforeEach(() => { }); describe("WalletFactory", () => { - it("should make a wallet with a single passphrase", () => { - const entity: Wallet = factory.get("Wallet").make() as Wallet; + it("should make a wallet", () => { + const entity: Wallets.Wallet = factory.get("Wallet").make(); - expect(entity).toContainAllKeys(["address", "publicKey", "privateKey", "wif", "passphrase"]); + expect(entity).toBeInstanceOf(Wallets.Wallet); expect(entity.address).toBeString(); expect(entity.publicKey).toBeString(); - expect(entity.privateKey).toBeString(); - expect(entity.wif).toBeString(); - expect(entity.passphrase).toBeString(); }); - it("should make a wallet with a second passphrase", () => { - const entity: Wallet = factory + it("should make a wallet with a second public key", () => { + const entity: Wallets.Wallet = factory .get("Wallet") - .withStates("secondPassphrase") - .make() as Wallet; - - expect(entity).toContainAllKeys([ - "address", - "publicKey", - "privateKey", - "wif", - "passphrase", - "secondPassphrase", - ]); + .withStates("secondPublicKey") + .make(); + + expect(entity).toBeInstanceOf(Wallets.Wallet); expect(entity.address).toBeString(); expect(entity.publicKey).toBeString(); - expect(entity.privateKey).toBeString(); - expect(entity.wif).toBeString(); - expect(entity.passphrase).toBeString(); - expect(entity.secondPassphrase).toBeString(); + expect(entity.getAttribute("secondPublicKey")).toBeString(); }); }); diff --git a/packages/core-test-framework/src/factories/factories/wallet.ts b/packages/core-test-framework/src/factories/factories/wallet.ts index 7bedcf51e2..cd4b751cff 100644 --- a/packages/core-test-framework/src/factories/factories/wallet.ts +++ b/packages/core-test-framework/src/factories/factories/wallet.ts @@ -1,25 +1,46 @@ +import { Services } from "@arkecosystem/core-kernel"; +import { Wallets } from "@arkecosystem/core-state"; import { Identities } from "@arkecosystem/crypto"; import { generateMnemonic } from "bip39"; import { FactoryBuilder } from "../factory-builder"; export const registerWalletFactory = (factory: FactoryBuilder): void => { - factory.set("Wallet", () => { - const passphrase: string = generateMnemonic(); + const knownAttributes: Services.Attributes.AttributeSet = new Services.Attributes.AttributeSet(); + knownAttributes.set("delegate.approval"); + knownAttributes.set("delegate.forgedFees"); + knownAttributes.set("delegate.forgedRewards"); + knownAttributes.set("delegate.forgedTotal"); + knownAttributes.set("delegate.lastBlock"); + knownAttributes.set("delegate.producedBlocks"); + knownAttributes.set("delegate.rank"); + knownAttributes.set("delegate.resigned"); + knownAttributes.set("delegate.round"); + knownAttributes.set("delegate.username"); + knownAttributes.set("delegate.voteBalance"); + knownAttributes.set("delegate"); + knownAttributes.set("htlc.lockedBalance"); + knownAttributes.set("htlc.locks"); + knownAttributes.set("ipfs.hashes"); + knownAttributes.set("ipfs"); + knownAttributes.set("multiSignature"); + knownAttributes.set("secondPublicKey"); + knownAttributes.set("vote"); - const { publicKey, privateKey } = Identities.Keys.fromPassphrase(passphrase); + factory.set("Wallet", ({ options }) => { + const passphrase: string = options.passphrase || generateMnemonic(); - return { - publicKey, - privateKey, - address: Identities.Address.fromPassphrase(passphrase), - wif: Identities.WIF.fromPassphrase(passphrase), - passphrase, - }; + const wallet: Wallets.Wallet = new Wallets.Wallet( + Identities.Address.fromPassphrase(passphrase), + new Services.Attributes.AttributeMap(knownAttributes), + ); + wallet.publicKey = Identities.PublicKey.fromPassphrase(passphrase); + + return wallet; }); - factory.get("Wallet").state("secondPassphrase", ({ entity }) => { - entity.secondPassphrase = generateMnemonic(); + factory.get("Wallet").state("secondPublicKey", ({ entity }) => { + entity.setAttribute("secondPublicKey", Identities.PublicKey.fromPassphrase(generateMnemonic())); return entity; });