Skip to content

Commit ce618cc

Browse files
authored
feat: Implement AIP36 (#3763)
1 parent eddb726 commit ce618cc

File tree

72 files changed

+3324
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+3324
-4
lines changed

.github/workflows/lint-test-benchmark.yml

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,160 @@ jobs:
10481048
env:
10491049
CORE_DB_DATABASE: ark_unitnet
10501050
CORE_DB_USERNAME: ark
1051+
test-functional-entity-register:
1052+
needs: lint
1053+
1054+
runs-on: ubuntu-latest
1055+
1056+
services:
1057+
postgres:
1058+
image: postgres:12
1059+
env:
1060+
POSTGRES_USER: ark
1061+
POSTGRES_PASSWORD: password
1062+
POSTGRES_DB: ark_unitnet
1063+
ports:
1064+
- 5432:5432
1065+
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
1066+
1067+
strategy:
1068+
matrix:
1069+
node-version: [12.x]
1070+
1071+
steps:
1072+
- uses: actions/checkout@v1
1073+
- name: Cache node modules
1074+
uses: actions/cache@v1
1075+
with:
1076+
path: node_modules
1077+
key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }}
1078+
restore-keys: ${{ runner.os }}-node-
1079+
- name: Use Node.js ${{ matrix.node-version }}
1080+
uses: actions/setup-node@v1
1081+
with:
1082+
node-version: ${{ matrix.node-version }}
1083+
1084+
- name: Update system
1085+
run: sudo apt-get update -y
1086+
1087+
- name: Install xsel & postgresql-client
1088+
run: sudo apt-get install -q xsel postgresql-client
1089+
1090+
- name: Install and build packages
1091+
run: yarn setup
1092+
1093+
- name: Create .core/database directory
1094+
run: mkdir -p $HOME/.core/database
1095+
1096+
- name: Functional tests
1097+
run: yarn test __tests__/functional/transaction-forging/entity-register.test.ts
1098+
1099+
env:
1100+
CORE_DB_DATABASE: ark_unitnet
1101+
CORE_DB_USERNAME: ark
1102+
test-functional-entity-resign:
1103+
needs: lint
1104+
1105+
runs-on: ubuntu-latest
1106+
1107+
services:
1108+
postgres:
1109+
image: postgres:12
1110+
env:
1111+
POSTGRES_USER: ark
1112+
POSTGRES_PASSWORD: password
1113+
POSTGRES_DB: ark_unitnet
1114+
ports:
1115+
- 5432:5432
1116+
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
1117+
1118+
strategy:
1119+
matrix:
1120+
node-version: [12.x]
1121+
1122+
steps:
1123+
- uses: actions/checkout@v1
1124+
- name: Cache node modules
1125+
uses: actions/cache@v1
1126+
with:
1127+
path: node_modules
1128+
key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }}
1129+
restore-keys: ${{ runner.os }}-node-
1130+
- name: Use Node.js ${{ matrix.node-version }}
1131+
uses: actions/setup-node@v1
1132+
with:
1133+
node-version: ${{ matrix.node-version }}
1134+
1135+
- name: Update system
1136+
run: sudo apt-get update -y
1137+
1138+
- name: Install xsel & postgresql-client
1139+
run: sudo apt-get install -q xsel postgresql-client
1140+
1141+
- name: Install and build packages
1142+
run: yarn setup
1143+
1144+
- name: Create .core/database directory
1145+
run: mkdir -p $HOME/.core/database
1146+
1147+
- name: Functional tests
1148+
run: yarn test __tests__/functional/transaction-forging/entity-resign.test.ts
1149+
1150+
env:
1151+
CORE_DB_DATABASE: ark_unitnet
1152+
CORE_DB_USERNAME: ark
1153+
test-functional-entity-update:
1154+
needs: lint
1155+
1156+
runs-on: ubuntu-latest
1157+
1158+
services:
1159+
postgres:
1160+
image: postgres:12
1161+
env:
1162+
POSTGRES_USER: ark
1163+
POSTGRES_PASSWORD: password
1164+
POSTGRES_DB: ark_unitnet
1165+
ports:
1166+
- 5432:5432
1167+
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
1168+
1169+
strategy:
1170+
matrix:
1171+
node-version: [12.x]
1172+
1173+
steps:
1174+
- uses: actions/checkout@v1
1175+
- name: Cache node modules
1176+
uses: actions/cache@v1
1177+
with:
1178+
path: node_modules
1179+
key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }}
1180+
restore-keys: ${{ runner.os }}-node-
1181+
- name: Use Node.js ${{ matrix.node-version }}
1182+
uses: actions/setup-node@v1
1183+
with:
1184+
node-version: ${{ matrix.node-version }}
1185+
1186+
- name: Update system
1187+
run: sudo apt-get update -y
1188+
1189+
- name: Install xsel & postgresql-client
1190+
run: sudo apt-get install -q xsel postgresql-client
1191+
1192+
- name: Install and build packages
1193+
run: yarn setup
1194+
1195+
- name: Create .core/database directory
1196+
run: mkdir -p $HOME/.core/database
1197+
1198+
- name: Functional tests
1199+
run: yarn test __tests__/functional/transaction-forging/entity-update.test.ts
1200+
1201+
env:
1202+
CORE_DB_DATABASE: ark_unitnet
1203+
CORE_DB_USERNAME: ark
1204+
10511205
test-e2e:
10521206
runs-on: ubuntu-latest
10531207

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
import "@arkecosystem/core-test-framework/src/matchers";
2+
3+
import { Contracts } from "@arkecosystem/core-kernel";
4+
import secrets from "@arkecosystem/core-test-framework/src/internal/passphrases.json";
5+
import { snoozeForBlock, TransactionFactory } from "@arkecosystem/core-test-framework/src/utils";
6+
7+
import * as support from "./__support__";
8+
import { Enums } from "@arkecosystem/core-magistrate-crypto";
9+
import { Identities } from "@arkecosystem/crypto";
10+
import { generateMnemonic } from "bip39";
11+
12+
let app: Contracts.Kernel.Application;
13+
beforeAll(async () => (app = await support.setUp()));
14+
afterAll(async () => await support.tearDown());
15+
16+
describe("Transaction Forging - Entity registration", () => {
17+
describe("Signed with 1 Passphrase", () => {
18+
it("should broadcast, accept and forge it [Signed with 1 Passphrase]", async () => {
19+
// Registering a desktop wallet plugin
20+
const entityRegistration = TransactionFactory.initialize(app)
21+
.entity({
22+
type: Enums.EntityType.Plugin,
23+
subType: Enums.EntitySubType.PluginDesktop,
24+
action: Enums.EntityAction.Register,
25+
data: {
26+
name: "my_plugin_for_desktop_wallet"
27+
}
28+
})
29+
.withPassphrase(secrets[0])
30+
.createOne();
31+
32+
await expect(entityRegistration).toBeAccepted();
33+
await snoozeForBlock(1);
34+
await expect(entityRegistration.id).toBeForged();
35+
36+
await expect(entityRegistration).entityRegistered();
37+
});
38+
39+
it("should reject entity registration, because entity name contains unicode control characters [Signed with 1 Passphrase]", async () => {
40+
// entity registration
41+
const entityRegistration = TransactionFactory.initialize(app)
42+
.entity({
43+
type: Enums.EntityType.Plugin,
44+
subType: Enums.EntitySubType.PluginDesktop,
45+
action: Enums.EntityAction.Register,
46+
data: {
47+
name: "\u0008name"
48+
}
49+
})
50+
.withPassphrase(secrets[0])
51+
.createOne();
52+
53+
await expect(entityRegistration).toBeRejected();
54+
await snoozeForBlock(1);
55+
await expect(entityRegistration.id).not.toBeForged();
56+
await expect(entityRegistration).not.entityRegistered();
57+
});
58+
});
59+
60+
describe("Signed with 2 Passphrases", () => {
61+
it("should broadcast, accept and forge it [Signed with 2 Passphrases] ", async () => {
62+
// Prepare a fresh wallet for the tests
63+
const passphrase = generateMnemonic();
64+
const secondPassphrase = generateMnemonic();
65+
66+
// Initial Funds
67+
const initialFunds = TransactionFactory.initialize(app)
68+
.transfer(Identities.Address.fromPassphrase(passphrase), 150 * 1e8)
69+
.withPassphrase(secrets[0])
70+
.createOne();
71+
72+
await expect(initialFunds).toBeAccepted();
73+
await snoozeForBlock(1);
74+
await expect(initialFunds.id).toBeForged();
75+
76+
// Register a second passphrase
77+
const secondSignature = TransactionFactory.initialize(app)
78+
.secondSignature(secondPassphrase)
79+
.withPassphrase(passphrase)
80+
.createOne();
81+
82+
await expect(secondSignature).toBeAccepted();
83+
await snoozeForBlock(1);
84+
await expect(secondSignature.id).toBeForged();
85+
86+
// Registering entity
87+
const entityRegistration = TransactionFactory.initialize(app)
88+
.entity({
89+
type: Enums.EntityType.Bridgechain,
90+
subType: Enums.EntitySubType.None,
91+
action: Enums.EntityAction.Register,
92+
data: {
93+
name: "my_bridgechain"
94+
}
95+
})
96+
.withPassphrase(passphrase)
97+
.withSecondPassphrase(secondPassphrase)
98+
.createOne();
99+
100+
await expect(entityRegistration).toBeAccepted();
101+
await snoozeForBlock(1);
102+
await expect(entityRegistration.id).toBeForged();
103+
await expect(entityRegistration).entityRegistered();
104+
});
105+
});
106+
107+
describe("Signed with multi signature [3 of 3]", () => {
108+
// Register a multi signature wallet with defaults
109+
const passphrase = generateMnemonic();
110+
const passphrases = [passphrase, secrets[4], secrets[5]];
111+
const participants = [
112+
Identities.PublicKey.fromPassphrase(passphrases[0]),
113+
Identities.PublicKey.fromPassphrase(passphrases[1]),
114+
Identities.PublicKey.fromPassphrase(passphrases[2]),
115+
];
116+
117+
it("should broadcast, accept and forge it [3-of-3 multisig]", async () => {
118+
// Funds to register a multi signature wallet
119+
const initialFunds = TransactionFactory.initialize(app)
120+
.transfer(Identities.Address.fromPassphrase(passphrase), 50 * 1e8)
121+
.withPassphrase(secrets[0])
122+
.createOne();
123+
124+
await expect(initialFunds).toBeAccepted();
125+
await snoozeForBlock(1);
126+
await expect(initialFunds.id).toBeForged();
127+
128+
// Registering a multi-signature wallet
129+
const multiSignature = TransactionFactory.initialize(app)
130+
.multiSignature(participants, 3)
131+
.withPassphrase(passphrase)
132+
.withPassphraseList(passphrases)
133+
.createOne();
134+
135+
await expect(multiSignature).toBeAccepted();
136+
await snoozeForBlock(1);
137+
await expect(multiSignature.id).toBeForged();
138+
139+
// Send funds to multi signature wallet
140+
const multiSigAddress = Identities.Address.fromMultiSignatureAsset(multiSignature.asset.multiSignature);
141+
const multiSigPublicKey = Identities.PublicKey.fromMultiSignatureAsset(multiSignature.asset.multiSignature);
142+
143+
const multiSignatureFunds = TransactionFactory.initialize(app)
144+
.transfer(multiSigAddress, 100 * 1e8)
145+
.withPassphrase(secrets[0])
146+
.createOne();
147+
148+
await expect(multiSignatureFunds).toBeAccepted();
149+
await snoozeForBlock(1);
150+
await expect(multiSignatureFunds.id).toBeForged();
151+
152+
// Registering entity
153+
const entityRegistration = TransactionFactory.initialize(app)
154+
.entity({
155+
type: Enums.EntityType.Developer,
156+
subType: Enums.EntitySubType.None,
157+
action: Enums.EntityAction.Register,
158+
data: {
159+
name: "iam_a_developer"
160+
}
161+
})
162+
.withSenderPublicKey(multiSigPublicKey)
163+
.withPassphraseList(passphrases)
164+
.createOne();
165+
166+
await expect(entityRegistration).toBeAccepted();
167+
await snoozeForBlock(1);
168+
await expect(entityRegistration.id).toBeForged();
169+
await expect(entityRegistration).entityRegistered();
170+
});
171+
});
172+
});

0 commit comments

Comments
 (0)