-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initial implementation of AIP18 (#2508)
- Loading branch information
1 parent
b611819
commit a4b9737
Showing
97 changed files
with
2,115 additions
and
1,068 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
__tests__/functional/transaction-forging/multi-signature-registration.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { Identities } from "@arkecosystem/crypto"; | ||
import { TransactionFactory } from "../../helpers/transaction-factory"; | ||
import { secrets } from "../../utils/config/testnet/delegates.json"; | ||
import * as support from "./__support__"; | ||
|
||
const { passphrase, secondPassphrase } = support.passphrases; | ||
|
||
beforeAll(support.setUp); | ||
afterAll(support.tearDown); | ||
|
||
describe("Transaction Forging - Multi Signature Registration", () => { | ||
it("should broadcast, accept and forge it [Signed with 1 Passphrase]", async () => { | ||
// Funds to register a multi signature wallet | ||
const initialFunds = TransactionFactory.transfer(Identities.Address.fromPassphrase(passphrase), 50 * 1e8) | ||
.withPassphrase(secrets[0]) | ||
.create(); | ||
|
||
await support.expectAcceptAndBroadcast(initialFunds, initialFunds[0].id); | ||
await support.snoozeForBlock(1); | ||
await support.expectTransactionForged(initialFunds[0].id); | ||
|
||
// Register a multi signature wallet with defaults | ||
const passphrases = [passphrase, secrets[1], secrets[2]]; | ||
const participants = [ | ||
Identities.PublicKey.fromPassphrase(passphrases[0]), | ||
Identities.PublicKey.fromPassphrase(passphrases[1]), | ||
Identities.PublicKey.fromPassphrase(passphrases[2]), | ||
]; | ||
|
||
const multiSignature = TransactionFactory.multiSignature(participants, 3) | ||
.withPassphrase(passphrase) | ||
.withPassphraseList(passphrases) | ||
.create(); | ||
|
||
await support.expectAcceptAndBroadcast(multiSignature, multiSignature[0].id); | ||
await support.snoozeForBlock(1); | ||
await support.expectTransactionForged(multiSignature[0].id); | ||
}); | ||
|
||
it("should broadcast, accept and forge it [Signed with 2 Passphrases]", async () => { | ||
const passphrase = secrets[2]; | ||
// Make a fresh wallet for the second signature tests | ||
const initialFunds = TransactionFactory.transfer(Identities.Address.fromPassphrase(passphrase), 100 * 1e8) | ||
.withPassphrase(secrets[0]) | ||
.create(); | ||
|
||
await support.expectAcceptAndBroadcast(initialFunds, initialFunds[0].id); | ||
await support.snoozeForBlock(1); | ||
await support.expectTransactionForged(initialFunds[0].id); | ||
|
||
// Register a second passphrase | ||
const secondSignature = TransactionFactory.secondSignature(secondPassphrase) | ||
.withPassphrase(passphrase) | ||
.create(); | ||
|
||
await support.expectAcceptAndBroadcast(secondSignature, secondSignature[0].id); | ||
await support.snoozeForBlock(1); | ||
await support.expectTransactionForged(secondSignature[0].id); | ||
|
||
// Register a multi signature wallet with defaults | ||
const passphrases = [passphrase, secrets[3], secrets[4]]; | ||
const participants = [ | ||
Identities.PublicKey.fromPassphrase(passphrases[0]), | ||
Identities.PublicKey.fromPassphrase(passphrases[1]), | ||
Identities.PublicKey.fromPassphrase(passphrases[2]), | ||
]; | ||
|
||
const multiSignature = TransactionFactory.multiSignature(participants, 3) | ||
.withPassphraseList(passphrases) | ||
.withPassphrasePair({ passphrase, secondPassphrase }) | ||
.create(); | ||
|
||
await support.expectAcceptAndBroadcast(multiSignature, multiSignature[0].id); | ||
await support.snoozeForBlock(1); | ||
await support.expectTransactionForged(multiSignature[0].id); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
__tests__/integration/core-tester-cli/commands/send/multi-signature-registration.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { httpie } from "@arkecosystem/core-utils"; | ||
import { Transactions } from "@arkecosystem/crypto"; | ||
import "jest-extended"; | ||
import nock from "nock"; | ||
import { MultiSignatureRegistrationCommand } from "../../../../../packages/core-tester-cli/src/commands/send/multi-signature-registration"; | ||
import { arkToSatoshi, captureTransactions, expectTransactions, toFlags } from "../../shared"; | ||
|
||
beforeEach(() => { | ||
// Just passthru. We'll test the Command class logic in its own test file more thoroughly | ||
nock("http://localhost:4003") | ||
.get("/api/v2/node/configuration") | ||
.thrice() | ||
.reply(200, { data: { constants: {} } }); | ||
|
||
nock("http://localhost:4000") | ||
.get("/config") | ||
.thrice() | ||
.reply(200, { data: { network: { name: "testnet" } } }); | ||
|
||
jest.spyOn(httpie, "get"); | ||
jest.spyOn(httpie, "post"); | ||
}); | ||
|
||
afterEach(() => { | ||
nock.cleanAll(); | ||
}); | ||
|
||
describe("Commands - Multi signature registration", () => { | ||
it("should apply multi signature", async () => { | ||
const opts = { | ||
multiSignatureFee: 1, | ||
number: 1, | ||
participants: | ||
"03287bfebba4c7881a0509717e71b34b63f31e40021c321f89ae04f84be6d6ac37," + | ||
"02def27da9336e7fbf63131b8d7e5c9f45b296235db035f1f4242c507398f0f21d," + | ||
"0290907d441d257334c4376126d6cbf37cd7993ca2d0cc58850b30b869d4bf4c3e", | ||
}; | ||
|
||
const expectedTransactions = []; | ||
captureTransactions(nock, expectedTransactions); | ||
|
||
await MultiSignatureRegistrationCommand.run(toFlags(opts)); | ||
|
||
expect(httpie.post).toHaveBeenCalledTimes(2); | ||
expectTransactions(expectedTransactions, { | ||
fee: arkToSatoshi(20), | ||
asset: { | ||
multiSignature: { | ||
min: 3, | ||
publicKeys: expect.toContainValues(opts.participants.split(",")), | ||
}, | ||
}, | ||
}); | ||
|
||
expect(Transactions.Verifier.verify(expectedTransactions[0])).toBeTrue(); | ||
}); | ||
}); |
Oops, something went wrong.