Skip to content

Commit

Permalink
feat(core-magistrate): AIP36 (#3836)
Browse files Browse the repository at this point in the history
  • Loading branch information
air1one committed Jun 27, 2020
1 parent c498ef0 commit 36c1ca7
Show file tree
Hide file tree
Showing 77 changed files with 3,370 additions and 4 deletions.
148 changes: 148 additions & 0 deletions .github/workflows/functional.yml
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,154 @@ jobs:
POSTGRES_DB: ark_unitnet
CORE_API_RATE_LIMIT_USER_LIMIT: 300

test-functional-entity-register:
runs-on: ubuntu-latest

services:
postgres:
image: postgres:12
env:
POSTGRES_USER: ark
POSTGRES_PASSWORD: password
POSTGRES_DB: ark_unitnet
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

strategy:
matrix:
node-version: [12.x]

steps:
- uses: actions/checkout@v1
- name: Cache node modules
uses: actions/cache@v1
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }}
restore-keys: ${{ runner.os }}-node-
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Update system
run: sudo apt-get update -y

- name: Install xsel & postgresql-client
run: sudo apt-get install -q xsel postgresql-client

- name: Install and build packages
run: yarn setup

- name: Create .core/database directory
run: mkdir -p $HOME/.core/database

- name: Functional tests
run: yarn test __tests__/functional/transaction-forging/entity-register.test.ts

env:
CORE_DB_DATABASE: ark_unitnet
CORE_DB_USERNAME: ark
test-functional-entity-resign:
runs-on: ubuntu-latest

services:
postgres:
image: postgres:12
env:
POSTGRES_USER: ark
POSTGRES_PASSWORD: password
POSTGRES_DB: ark_unitnet
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

strategy:
matrix:
node-version: [12.x]

steps:
- uses: actions/checkout@v1
- name: Cache node modules
uses: actions/cache@v1
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }}
restore-keys: ${{ runner.os }}-node-
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Update system
run: sudo apt-get update -y

- name: Install xsel & postgresql-client
run: sudo apt-get install -q xsel postgresql-client

- name: Install and build packages
run: yarn setup

- name: Create .core/database directory
run: mkdir -p $HOME/.core/database

- name: Functional tests
run: yarn test __tests__/functional/transaction-forging/entity-resign.test.ts

env:
CORE_DB_DATABASE: ark_unitnet
CORE_DB_USERNAME: ark
test-functional-entity-update:
runs-on: ubuntu-latest

services:
postgres:
image: postgres:12
env:
POSTGRES_USER: ark
POSTGRES_PASSWORD: password
POSTGRES_DB: ark_unitnet
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

strategy:
matrix:
node-version: [12.x]

steps:
- uses: actions/checkout@v1
- name: Cache node modules
uses: actions/cache@v1
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }}
restore-keys: ${{ runner.os }}-node-
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Update system
run: sudo apt-get update -y

- name: Install xsel & postgresql-client
run: sudo apt-get install -q xsel postgresql-client

- name: Install and build packages
run: yarn setup

- name: Create .core/database directory
run: mkdir -p $HOME/.core/database

- name: Functional tests
run: yarn test __tests__/functional/transaction-forging/entity-update.test.ts

env:
CORE_DB_DATABASE: ark_unitnet
CORE_DB_USERNAME: ark

pool:
runs-on: ubuntu-latest

Expand Down
167 changes: 167 additions & 0 deletions __tests__/functional/transaction-forging/entity-register.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
import { Enums } from "@arkecosystem/core-magistrate-crypto";
import { Identities } from "@arkecosystem/crypto";
import { generateMnemonic } from "bip39";
import { TransactionFactory } from "../../helpers/transaction-factory";
import { secrets } from "../../utils/config/testnet/delegates.json";

import * as support from "./__support__";

beforeAll(async () => await support.setUp());
afterAll(async () => await support.tearDown());

describe("Transaction Forging - Entity registration", () => {
describe("Signed with 1 Passphrase", () => {
it("should broadcast, accept and forge it [Signed with 1 Passphrase]", async () => {
// Registering a desktop wallet plugin
const entityRegistration = TransactionFactory.entity({
type: Enums.EntityType.Plugin,
subType: Enums.EntitySubType.PluginDesktop,
action: Enums.EntityAction.Register,
data: {
name: "my_plugin_for_desktop_wallet",
},
})
.withPassphrase(secrets[0])
.createOne();

await expect(entityRegistration).not.toBeAccepted(); // aip36 not here yet
await support.snoozeForBlock(1);
await expect(entityRegistration.id).not.toBeForged();

for (let i = 0; i < 30; i++) {
await support.snoozeForBlock(1); // wait for aip36 to kick in, todo better way without waiting ? (snapshot ?)
}

await expect(entityRegistration).toBeAccepted();
await support.snoozeForBlock(1);
await expect(entityRegistration.id).toBeForged();

await expect(entityRegistration).entityRegistered();
});

it("should reject entity registration, because entity name contains unicode control characters [Signed with 1 Passphrase]", async () => {
// entity registration
const entityRegistration = TransactionFactory.entity({
type: Enums.EntityType.Plugin,
subType: Enums.EntitySubType.PluginDesktop,
action: Enums.EntityAction.Register,
data: {
name: "\u0008name",
},
})
.withPassphrase(secrets[0])
.createOne();

await expect(entityRegistration).toBeRejected();
await support.snoozeForBlock(1);
await expect(entityRegistration.id).not.toBeForged();
await expect(entityRegistration).not.entityRegistered();
});
});

describe("Signed with 2 Passphrases", () => {
it("should broadcast, accept and forge it [Signed with 2 Passphrases] ", async () => {
// Prepare a fresh wallet for the tests
const passphrase = generateMnemonic();
const secondPassphrase = generateMnemonic();

// Initial Funds
const initialFunds = TransactionFactory.transfer(Identities.Address.fromPassphrase(passphrase), 150 * 1e8)
.withPassphrase(secrets[0])
.createOne();

await expect(initialFunds).toBeAccepted();
await support.snoozeForBlock(1);
await expect(initialFunds.id).toBeForged();

// Register a second passphrase
const secondSignature = TransactionFactory.secondSignature(secondPassphrase)
.withPassphrase(passphrase)
.createOne();

await expect(secondSignature).toBeAccepted();
await support.snoozeForBlock(1);
await expect(secondSignature.id).toBeForged();

// Registering entity
const entityRegistration = TransactionFactory.entity({
type: Enums.EntityType.Bridgechain,
subType: Enums.EntitySubType.None,
action: Enums.EntityAction.Register,
data: {
name: "my_bridgechain",
},
})
.withPassphrase(passphrase)
.withSecondPassphrase(secondPassphrase)
.createOne();

await expect(entityRegistration).toBeAccepted();
await support.snoozeForBlock(1);
await expect(entityRegistration.id).toBeForged();
await expect(entityRegistration).entityRegistered();
});
});

describe("Signed with multi signature [3 of 3]", () => {
// Register a multi signature wallet with defaults
const passphrase = generateMnemonic();
const passphrases = [passphrase, secrets[4], secrets[5]];
const participants = [
Identities.PublicKey.fromPassphrase(passphrases[0]),
Identities.PublicKey.fromPassphrase(passphrases[1]),
Identities.PublicKey.fromPassphrase(passphrases[2]),
];

it("should broadcast, accept and forge it [3-of-3 multisig]", async () => {
// Funds to register a multi signature wallet
const initialFunds = TransactionFactory.transfer(Identities.Address.fromPassphrase(passphrase), 50 * 1e8)
.withPassphrase(secrets[0])
.createOne();

await expect(initialFunds).toBeAccepted();
await support.snoozeForBlock(1);
await expect(initialFunds.id).toBeForged();

// Registering a multi-signature wallet
const multiSignature = TransactionFactory.multiSignature(participants, 3)
.withPassphrase(passphrase)
.withPassphraseList(passphrases)
.createOne();

await expect(multiSignature).toBeAccepted();
await support.snoozeForBlock(1);
await expect(multiSignature.id).toBeForged();

// Send funds to multi signature wallet
const multiSigAddress = Identities.Address.fromMultiSignatureAsset(multiSignature.asset.multiSignature);
const multiSigPublicKey = Identities.PublicKey.fromMultiSignatureAsset(multiSignature.asset.multiSignature);

const multiSignatureFunds = TransactionFactory.transfer(multiSigAddress, 100 * 1e8)
.withPassphrase(secrets[0])
.createOne();

await expect(multiSignatureFunds).toBeAccepted();
await support.snoozeForBlock(1);
await expect(multiSignatureFunds.id).toBeForged();

// Registering entity
const entityRegistration = TransactionFactory.entity({
type: Enums.EntityType.Developer,
subType: Enums.EntitySubType.None,
action: Enums.EntityAction.Register,
data: {
name: "iam_a_developer",
},
})
.withSenderPublicKey(multiSigPublicKey)
.withPassphraseList(passphrases)
.createOne();

await expect(entityRegistration).toBeAccepted();
await support.snoozeForBlock(1);
await expect(entityRegistration.id).toBeForged();
await expect(entityRegistration).entityRegistered();
});
});
});

0 comments on commit 36c1ca7

Please sign in to comment.