Skip to content

Commit 710949d

Browse files
committed
Added MosaicRestriction Http & Tests
1 parent 7071512 commit 710949d

File tree

49 files changed

+1579
-917
lines changed

Some content is hidden

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

49 files changed

+1579
-917
lines changed

e2e/infrastructure/AccountHttp.spec.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@ import {deepEqual} from 'assert';
1818
import {assert, expect} from 'chai';
1919
import {AccountHttp} from '../../src/infrastructure/AccountHttp';
2020
import { Listener, TransactionHttp } from '../../src/infrastructure/infrastructure';
21+
import { RestrictionHttp } from '../../src/infrastructure/RestrictionHttp';
2122
import { Account } from '../../src/model/account/Account';
22-
import { AccountRestrictionModificationAction } from '../../src/model/account/AccountRestrictionModificationAction';
23-
import { AccountRestrictionType } from '../../src/model/account/AccountRestrictionType';
2423
import {Address} from '../../src/model/account/Address';
2524
import {PublicAccount} from '../../src/model/account/PublicAccount';
2625
import {NetworkType} from '../../src/model/blockchain/NetworkType';
2726
import { PlainMessage } from '../../src/model/message/PlainMessage';
2827
import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic';
2928
import { AliasAction } from '../../src/model/namespace/AliasAction';
3029
import { NamespaceId } from '../../src/model/namespace/NamespaceId';
30+
import { AccountRestrictionModificationAction } from '../../src/model/restriction/AccountRestrictionModificationAction';
31+
import { AccountRestrictionType } from '../../src/model/restriction/AccountRestrictionType';
3132
import { AccountRestrictionModification } from '../../src/model/transaction/AccountRestrictionModification';
3233
import { AccountRestrictionTransaction } from '../../src/model/transaction/AccountRestrictionTransaction';
3334
import { AddressAliasTransaction } from '../../src/model/transaction/AddressAliasTransaction';
@@ -52,6 +53,7 @@ describe('AccountHttp', () => {
5253
let accountPublicKey: string;
5354
let publicAccount: PublicAccount;
5455
let accountHttp: AccountHttp;
56+
let restrictionHttp: RestrictionHttp;
5557
let transactionHttp: TransactionHttp;
5658
let namespaceId: NamespaceId;
5759
let generationHash: string;
@@ -78,6 +80,7 @@ describe('AccountHttp', () => {
7880
generationHash = json.generationHash;
7981
accountHttp = new AccountHttp(json.apiUrl);
8082
transactionHttp = new TransactionHttp(json.apiUrl);
83+
restrictionHttp = new RestrictionHttp(json.apiUrl);
8184
done();
8285
});
8386
});
@@ -284,7 +287,7 @@ describe('AccountHttp', () => {
284287
describe('getAccountRestrictions', () => {
285288
it('should call getAccountRestrictions successfully', (done) => {
286289
setTimeout(() => {
287-
accountHttp.getAccountRestrictions(accountAddress).subscribe((accountRestrictions) => {
290+
restrictionHttp.getAccountRestrictions(accountAddress).subscribe((accountRestrictions) => {
288291
deepEqual(accountRestrictions.accountRestrictions.address, accountAddress);
289292
done();
290293
});
@@ -295,7 +298,7 @@ describe('AccountHttp', () => {
295298
describe('getAccountRestrictionsFromAccounts', () => {
296299
it('should call getAccountRestrictionsFromAccounts successfully', (done) => {
297300
setTimeout(() => {
298-
accountHttp.getAccountRestrictionsFromAccounts([accountAddress]).subscribe((accountRestrictions) => {
301+
restrictionHttp.getAccountRestrictionsFromAccounts([accountAddress]).subscribe((accountRestrictions) => {
299302
deepEqual(accountRestrictions[0]!.accountRestrictions.address, accountAddress);
300303
done();
301304
});
Lines changed: 312 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,312 @@
1+
/*
2+
* Copyright 2018 NEM
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import {deepEqual} from 'assert';
18+
import {assert} from 'chai';
19+
import {AccountHttp} from '../../src/infrastructure/AccountHttp';
20+
import { Listener, TransactionHttp } from '../../src/infrastructure/infrastructure';
21+
import { RestrictionHttp } from '../../src/infrastructure/RestrictionHttp';
22+
import { Account } from '../../src/model/account/Account';
23+
import {Address} from '../../src/model/account/Address';
24+
import {PublicAccount} from '../../src/model/account/PublicAccount';
25+
import {NetworkType} from '../../src/model/blockchain/NetworkType';
26+
import { MosaicFlags } from '../../src/model/mosaic/MosaicFlags';
27+
import { MosaicId } from '../../src/model/mosaic/MosaicId';
28+
import { MosaicNonce } from '../../src/model/mosaic/MosaicNonce';
29+
import { AccountRestrictionModificationAction } from '../../src/model/restriction/AccountRestrictionModificationAction';
30+
import { AccountRestrictionType } from '../../src/model/restriction/AccountRestrictionType';
31+
import { MosaicRestrictionEntryType } from '../../src/model/restriction/MosaicRestrictionEntryType';
32+
import { MosaicRestrictionType } from '../../src/model/restriction/MosaicRestrictionType';
33+
import { AccountRestrictionModification } from '../../src/model/transaction/AccountRestrictionModification';
34+
import { AccountRestrictionTransaction } from '../../src/model/transaction/AccountRestrictionTransaction';
35+
import { AggregateTransaction } from '../../src/model/transaction/AggregateTransaction';
36+
import { Deadline } from '../../src/model/transaction/Deadline';
37+
import { MosaicAddressRestrictionTransaction } from '../../src/model/transaction/MosaicAddressRestrictionTransaction';
38+
import { MosaicDefinitionTransaction } from '../../src/model/transaction/MosaicDefinitionTransaction';
39+
import { MosaicGlobalRestrictionTransaction } from '../../src/model/transaction/MosaicGlobalRestrictionTransaction';
40+
import { Transaction } from '../../src/model/transaction/Transaction';
41+
import { UInt64 } from '../../src/model/UInt64';
42+
43+
describe('RestrictionHttp', () => {
44+
let account: Account;
45+
let account2: Account;
46+
let account3: Account;
47+
let multisigAccount: Account;
48+
let cosignAccount1: Account;
49+
let cosignAccount2: Account;
50+
let cosignAccount3: Account;
51+
let accountAddress: Address;
52+
let accountPublicKey: string;
53+
let publicAccount: PublicAccount;
54+
let accountHttp: AccountHttp;
55+
let restrictionHttp: RestrictionHttp;
56+
let transactionHttp: TransactionHttp;
57+
let mosaicId: MosaicId;
58+
let generationHash: string;
59+
let config;
60+
61+
before((done) => {
62+
const path = require('path');
63+
require('fs').readFile(path.resolve(__dirname, '../conf/network.conf'), (err, data) => {
64+
if (err) {
65+
throw err;
66+
}
67+
const json = JSON.parse(data);
68+
config = json;
69+
account = Account.createFromPrivateKey(json.testAccount.privateKey, NetworkType.MIJIN_TEST);
70+
account2 = Account.createFromPrivateKey(json.testAccount2.privateKey, NetworkType.MIJIN_TEST);
71+
account3 = Account.createFromPrivateKey(json.testAccount3.privateKey, NetworkType.MIJIN_TEST);
72+
multisigAccount = Account.createFromPrivateKey(json.multisigAccount.privateKey, NetworkType.MIJIN_TEST);
73+
cosignAccount1 = Account.createFromPrivateKey(json.cosignatoryAccount.privateKey, NetworkType.MIJIN_TEST);
74+
cosignAccount2 = Account.createFromPrivateKey(json.cosignatory2Account.privateKey, NetworkType.MIJIN_TEST);
75+
cosignAccount3 = Account.createFromPrivateKey(json.cosignatory3Account.privateKey, NetworkType.MIJIN_TEST);
76+
accountAddress = Address.createFromRawAddress(json.testAccount.address);
77+
accountPublicKey = json.testAccount.publicKey;
78+
publicAccount = PublicAccount.createFromPublicKey(json.testAccount.publicKey, NetworkType.MIJIN_TEST);
79+
generationHash = json.generationHash;
80+
accountHttp = new AccountHttp(json.apiUrl);
81+
transactionHttp = new TransactionHttp(json.apiUrl);
82+
restrictionHttp = new RestrictionHttp(json.apiUrl);
83+
done();
84+
});
85+
});
86+
87+
/**
88+
* =========================
89+
* Setup test data
90+
* =========================
91+
*/
92+
describe('MosaicDefinitionTransaction', () => {
93+
let listener: Listener;
94+
before (() => {
95+
listener = new Listener(config.apiUrl);
96+
return listener.open();
97+
});
98+
after(() => {
99+
return listener.close();
100+
});
101+
it('standalone', (done) => {
102+
const nonce = MosaicNonce.createRandom();
103+
mosaicId = MosaicId.createFromNonce(nonce, account.publicAccount);
104+
const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create(
105+
Deadline.create(),
106+
nonce,
107+
mosaicId,
108+
MosaicFlags.create( true, true, true),
109+
3,
110+
UInt64.fromUint(1000),
111+
NetworkType.MIJIN_TEST,
112+
);
113+
const signedTransaction = mosaicDefinitionTransaction.signWith(account, generationHash);
114+
listener.confirmed(account.address).subscribe(() => {
115+
done();
116+
});
117+
listener.status(account.address).subscribe((error) => {
118+
console.log('Error:', error);
119+
assert(false);
120+
done();
121+
});
122+
transactionHttp.announce(signedTransaction);
123+
});
124+
});
125+
126+
describe('Setup Test AccountAddressRestriction', () => {
127+
let listener: Listener;
128+
before (() => {
129+
listener = new Listener(config.apiUrl);
130+
return listener.open();
131+
});
132+
after(() => {
133+
return listener.close();
134+
});
135+
136+
it('Announce AccountRestrictionTransaction', (done) => {
137+
const addressPropertyFilter = AccountRestrictionModification.createForAddress(
138+
AccountRestrictionModificationAction.Add,
139+
account3.address,
140+
);
141+
const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction(
142+
Deadline.create(),
143+
AccountRestrictionType.AllowIncomingAddress,
144+
[addressPropertyFilter],
145+
NetworkType.MIJIN_TEST,
146+
);
147+
const signedTransaction = addressModification.signWith(account, generationHash);
148+
listener.confirmed(account.address).subscribe(() => {
149+
done();
150+
});
151+
listener.status(account.address).subscribe((error) => {
152+
console.log('Error:', error);
153+
assert(false);
154+
done();
155+
});
156+
transactionHttp.announce(signedTransaction);
157+
});
158+
});
159+
160+
describe('MosaicGlobalRestrictionTransaction', () => {
161+
let listener: Listener;
162+
before (() => {
163+
listener = new Listener(config.apiUrl);
164+
return listener.open();
165+
});
166+
after(() => {
167+
return listener.close();
168+
});
169+
170+
it('standalone', (done) => {
171+
const mosaicGlobalRestrictionTransaction = MosaicGlobalRestrictionTransaction.create(
172+
Deadline.create(),
173+
mosaicId,
174+
UInt64.fromUint(60641),
175+
UInt64.fromUint(0),
176+
MosaicRestrictionType.NONE,
177+
UInt64.fromUint(0),
178+
MosaicRestrictionType.GE,
179+
NetworkType.MIJIN_TEST,
180+
);
181+
const signedTransaction = mosaicGlobalRestrictionTransaction.signWith(account, generationHash);
182+
183+
listener.confirmed(account.address).subscribe(() => {
184+
done();
185+
});
186+
listener.status(account.address).subscribe((error) => {
187+
console.log('Error:', error);
188+
assert(false);
189+
done();
190+
});
191+
transactionHttp.announce(signedTransaction);
192+
});
193+
});
194+
195+
describe('MosaicAddressRestrictionTransaction', () => {
196+
let listener: Listener;
197+
before (() => {
198+
listener = new Listener(config.apiUrl);
199+
return listener.open();
200+
});
201+
after(() => {
202+
return listener.close();
203+
});
204+
it('aggregate', (done) => {
205+
const mosaicAddressRestrictionTransaction = MosaicAddressRestrictionTransaction.create(
206+
Deadline.create(),
207+
mosaicId,
208+
UInt64.fromUint(60641),
209+
account3.address,
210+
UInt64.fromUint(2),
211+
NetworkType.MIJIN_TEST,
212+
);
213+
const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(),
214+
[mosaicAddressRestrictionTransaction.toAggregate(account.publicAccount)],
215+
NetworkType.MIJIN_TEST,
216+
[],
217+
);
218+
const signedTransaction = aggregateTransaction.signWith(account, generationHash);
219+
listener.confirmed(account.address).subscribe(() => {
220+
done();
221+
});
222+
listener.status(account.address).subscribe((error) => {
223+
console.log('Error:', error);
224+
assert(false);
225+
done();
226+
});
227+
transactionHttp.announce(signedTransaction);
228+
});
229+
});
230+
231+
/**
232+
* =========================
233+
* Tests
234+
* =========================
235+
*/
236+
237+
describe('getAccountRestrictions', () => {
238+
it('should call getAccountRestrictions successfully', (done) => {
239+
setTimeout(() => {
240+
restrictionHttp.getAccountRestrictions(accountAddress).subscribe((accountRestrictions) => {
241+
deepEqual(accountRestrictions.accountRestrictions.address, accountAddress);
242+
done();
243+
});
244+
}, 1000);
245+
});
246+
});
247+
248+
describe('getAccountRestrictionsFromAccounts', () => {
249+
it('should call getAccountRestrictionsFromAccounts successfully', (done) => {
250+
setTimeout(() => {
251+
restrictionHttp.getAccountRestrictionsFromAccounts([accountAddress]).subscribe((accountRestrictions) => {
252+
deepEqual(accountRestrictions[0]!.accountRestrictions.address, accountAddress);
253+
done();
254+
});
255+
}, 1000);
256+
});
257+
});
258+
259+
describe('getMosaicAddressRestriction', () => {
260+
it('should call getMosaicAddressRestriction successfully', (done) => {
261+
setTimeout(() => {
262+
restrictionHttp.getMosaicAddressRestriction(mosaicId, accountAddress).subscribe((mosaicRestriction) => {
263+
deepEqual(mosaicRestriction.mosaicId.toHex(), mosaicId.toHex());
264+
deepEqual(mosaicRestriction.entryType, MosaicRestrictionEntryType.ADDRESS);
265+
deepEqual(mosaicRestriction.targetAddress.plain(), accountAddress.plain());
266+
deepEqual(mosaicRestriction.restrictions[0].get(UInt64.fromUint(60641).toHex()), UInt64.fromUint(2).toString());
267+
done();
268+
});
269+
}, 1000);
270+
});
271+
});
272+
273+
describe('getMosaicAddressRestrictions', () => {
274+
it('should call getMosaicAddressRestrictions successfully', (done) => {
275+
setTimeout(() => {
276+
restrictionHttp.getMosaicAddressRestrictions(mosaicId, [accountAddress]).subscribe((mosaicRestriction) => {
277+
deepEqual(mosaicRestriction[0].mosaicId.toHex(), mosaicId.toHex());
278+
deepEqual(mosaicRestriction[0].entryType, MosaicRestrictionEntryType.ADDRESS);
279+
deepEqual(mosaicRestriction[0].targetAddress.plain(), accountAddress.plain());
280+
deepEqual(mosaicRestriction[0].restrictions[0].get(UInt64.fromUint(60641).toHex()), UInt64.fromUint(2).toString());
281+
done();
282+
});
283+
}, 1000);
284+
});
285+
});
286+
287+
describe('getMosaicGlobalRestriction', () => {
288+
it('should call getMosaicGlobalRestriction successfully', (done) => {
289+
setTimeout(() => {
290+
restrictionHttp.getMosaicGlobalRestriction(mosaicId).subscribe((mosaicRestriction) => {
291+
deepEqual(mosaicRestriction.mosaicId.toHex(), mosaicId.toHex());
292+
deepEqual(mosaicRestriction.entryType, MosaicRestrictionEntryType.GLOBAL);
293+
deepEqual(mosaicRestriction.restrictions[0].get(UInt64.fromUint(60641).toHex()), UInt64.fromUint(2).toString());
294+
done();
295+
});
296+
}, 1000);
297+
});
298+
});
299+
300+
describe('getMosaicGlobalRestrictions', () => {
301+
it('should call getMosaicGlobalRestrictions successfully', (done) => {
302+
setTimeout(() => {
303+
restrictionHttp.getMosaicGlobalRestrictions([mosaicId]).subscribe((mosaicRestriction) => {
304+
deepEqual(mosaicRestriction[0].mosaicId.toHex(), mosaicId.toHex());
305+
deepEqual(mosaicRestriction[0].entryType, MosaicRestrictionEntryType.GLOBAL);
306+
deepEqual(mosaicRestriction[0].restrictions[0].get(UInt64.fromUint(60641).toHex()), UInt64.fromUint(2).toString());
307+
done();
308+
});
309+
}, 1000);
310+
});
311+
});
312+
});

e2e/infrastructure/TransactionHttp.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ import { NamespaceHttp } from '../../src/infrastructure/infrastructure';
2525
import {Listener} from '../../src/infrastructure/Listener';
2626
import {TransactionHttp} from '../../src/infrastructure/TransactionHttp';
2727
import {Account} from '../../src/model/account/Account';
28-
import { AccountRestrictionModificationAction } from '../../src/model/account/AccountRestrictionModificationAction';
29-
import { AccountRestrictionType } from '../../src/model/account/AccountRestrictionType';
3028
import {NetworkType} from '../../src/model/blockchain/NetworkType';
3129
import { PlainMessage } from '../../src/model/message/PlainMessage';
3230
import { Mosaic } from '../../src/model/mosaic/Mosaic';
3331
import {MosaicFlags} from '../../src/model/mosaic/MosaicFlags';
3432
import {MosaicId} from '../../src/model/mosaic/MosaicId';
3533
import {MosaicNonce} from '../../src/model/mosaic/MosaicNonce';
36-
import { MosaicRestrictionType } from '../../src/model/mosaic/MosaicRestrictionType';
3734
import {MosaicSupplyChangeAction} from '../../src/model/mosaic/MosaicSupplyChangeAction';
3835
import {NetworkCurrencyMosaic} from '../../src/model/mosaic/NetworkCurrencyMosaic';
3936
import { AliasAction } from '../../src/model/namespace/AliasAction';
4037
import { NamespaceId } from '../../src/model/namespace/NamespaceId';
38+
import { AccountRestrictionModificationAction } from '../../src/model/restriction/AccountRestrictionModificationAction';
39+
import { AccountRestrictionType } from '../../src/model/restriction/AccountRestrictionType';
40+
import { MosaicRestrictionType } from '../../src/model/restriction/MosaicRestrictionType';
4141
import { AccountAddressRestrictionTransaction } from '../../src/model/transaction/AccountAddressRestrictionTransaction';
4242
import { AccountLinkTransaction } from '../../src/model/transaction/AccountLinkTransaction';
4343
import { AccountMetadataTransaction } from '../../src/model/transaction/AccountMetadataTransaction';

0 commit comments

Comments
 (0)