Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into merkle_proof
Browse files Browse the repository at this point in the history
# Conflicts:
#	e2e/infrastructure/IntegrationTestHelper.ts
#	package-lock.json
#	package.json
#	src/infrastructure/RestrictionAccountRepository.ts
#	src/infrastructure/TransactionRepository.ts
#	test/model/account/AccountInfo.spec.ts
  • Loading branch information
fboucquez committed Nov 27, 2020
2 parents f0779a7 + 1888cd0 commit 52e81a5
Show file tree
Hide file tree
Showing 48 changed files with 1,408 additions and 808 deletions.
2 changes: 1 addition & 1 deletion e2e/infrastructure/AccountHttp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ describe('AccountHttp', () => {
const accountInfo = await accountRepository.getAccountInfo(accountAddress).toPromise();
expect(accountInfo.publicKey).to.be.equal(accountPublicKey);

const merkleInfo = await accountRepository.getAccountsInfoMerkle(accountInfo.address).toPromise();
const merkleInfo = await accountRepository.getAccountInfoMerkle(accountInfo.address).toPromise();
expect(merkleInfo.raw).to.not.be.undefined;
});
});
Expand Down
38 changes: 19 additions & 19 deletions e2e/infrastructure/RestrictionHttp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@

import { deepEqual } from 'assert';
import { expect } from 'chai';
import { RestrictionAccountRepository } from '../../src/infrastructure/RestrictionAccountRepository';
import { RestrictionMosaicRepository } from '../../src/infrastructure/RestrictionMosaicRepository';
import { Account } from '../../src/model/account/Account';
import { Address } from '../../src/model/account/Address';
import { MosaicFlags } from '../../src/model/mosaic/MosaicFlags';
import { MosaicId } from '../../src/model/mosaic/MosaicId';
import { MosaicNonce } from '../../src/model/mosaic/MosaicNonce';
import { NetworkType } from '../../src/model/network/NetworkType';
import { AddressRestrictionFlag } from '../../src/model/restriction/AddressRestrictionFlag';
import { MosaicAddressRestriction } from '../../src/model/restriction/MosaicAddressRestriction';
import { MosaicRestrictionEntryType } from '../../src/model/restriction/MosaicRestrictionEntryType';
import { MosaicRestrictionType } from '../../src/model/restriction/MosaicRestrictionType';
import { AccountRestrictionTransaction } from '../../src/model/transaction/AccountRestrictionTransaction';
import { AggregateTransaction } from '../../src/model/transaction/AggregateTransaction';
import { Deadline } from '../../src/model/transaction/Deadline';
import { MosaicAddressRestrictionTransaction } from '../../src/model/transaction/MosaicAddressRestrictionTransaction';
import { MosaicDefinitionTransaction } from '../../src/model/transaction/MosaicDefinitionTransaction';
import { MosaicGlobalRestrictionTransaction } from '../../src/model/transaction/MosaicGlobalRestrictionTransaction';
import { UInt64 } from '../../src/model/UInt64';
import { RestrictionAccountRepository, RestrictionMosaicRepository } from '../../src/infrastructure';
import { UInt64 } from '../../src/model';
import { Account, Address } from '../../src/model/account';
import { MosaicFlags, MosaicId, MosaicNonce } from '../../src/model/mosaic';
import { NetworkType } from '../../src/model/network';
import {
AddressRestrictionFlag,
MosaicAddressRestriction,
MosaicRestrictionEntryType,
MosaicRestrictionType,
} from '../../src/model/restriction';
import {
AccountRestrictionTransaction,
AggregateTransaction,
Deadline,
MosaicAddressRestrictionTransaction,
MosaicDefinitionTransaction,
MosaicGlobalRestrictionTransaction,
} from '../../src/model/transaction';
import { IntegrationTestHelper } from './IntegrationTestHelper';

describe('RestrictionHttp', () => {
Expand Down
34 changes: 32 additions & 2 deletions e2e/infrastructure/TransactionHttp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
TransactionStatusRepository,
} from '../../src/infrastructure';
import { TransactionPaginationStreamer } from '../../src/infrastructure/paginationStreamer';
import { UInt64 } from '../../src/model';
import { TransactionVersion, UInt64, VotingKeyLinkV1Transaction } from '../../src/model';
import { Account } from '../../src/model/account';
import { LockHashAlgorithm } from '../../src/model/lock';
import { PlainMessage } from '../../src/model/message';
Expand Down Expand Up @@ -102,6 +102,7 @@ describe('TransactionHttp', () => {
let transactionRepository: TransactionRepository;
let transactionStatusRepository: TransactionStatusRepository;
let votingKey: string;
let votingKeyV1: string;

const remoteAccount = Account.generateNewAccount(helper.networkType);

Expand All @@ -115,7 +116,8 @@ describe('TransactionHttp', () => {
harvestingAccount = helper.harvestingAccount;
generationHash = helper.generationHash;
networkType = helper.networkType;
votingKey = Convert.uint8ToHex(Crypto.randomBytes(48));
votingKey = Convert.uint8ToHex(Crypto.randomBytes(32));
votingKeyV1 = Convert.uint8ToHex(Crypto.randomBytes(48));
namespaceRepository = helper.repositoryFactory.createNamespaceRepository();
transactionRepository = helper.repositoryFactory.createTransactionRepository();
transactionStatusRepository = helper.repositoryFactory.createTransactionStatusRepository();
Expand Down Expand Up @@ -735,10 +737,12 @@ describe('TransactionHttp', () => {
300,
LinkAction.Link,
networkType,
TransactionVersion.VOTING_KEY_LINK_V2,
helper.maxFee,
);
const signedTransaction = votingLinkTransaction.signWith(account, generationHash);

console.log(signedTransaction.payload);
return helper.announce(signedTransaction).then((transaction: VotingKeyLinkTransaction) => {
expect(transaction.linkedPublicKey, 'LinkedPublicKey').not.to.be.undefined;
expect(transaction.startEpoch, 'startEpoch').not.to.be.undefined;
Expand All @@ -748,6 +752,31 @@ describe('TransactionHttp', () => {
});
});
});

describe('VotingKeyLinkV1Transaction', () => {
it('standalone', () => {
const votingLinkTransaction = VotingKeyLinkV1Transaction.create(
Deadline.create(helper.epochAdjustment),
votingKeyV1,
100,
300,
LinkAction.Link,
networkType,
helper.maxFee,
);
const signedTransaction = votingLinkTransaction.signWith(account, generationHash);

console.log(signedTransaction.payload);

return helper.announce(signedTransaction).then((transaction: VotingKeyLinkV1Transaction) => {
expect(transaction.linkedPublicKey, 'LinkedPublicKey').not.to.be.undefined;
expect(transaction.startEpoch, 'startEpoch').not.to.be.undefined;
expect(transaction.endEpoch, 'endEpoch').not.to.be.undefined;
expect(transaction.linkAction, 'LinkAction').not.to.be.undefined;
return signedTransaction;
});
});
});
describe('VotingKeyLinkTransaction', () => {
it('aggregate', () => {
const votingLinkTransaction = VotingKeyLinkTransaction.create(
Expand All @@ -757,6 +786,7 @@ describe('TransactionHttp', () => {
300,
LinkAction.Unlink,
networkType,
TransactionVersion.VOTING_KEY_LINK_V2,
helper.maxFee,
);
const aggregateTransaction = AggregateTransaction.createComplete(
Expand Down
27 changes: 19 additions & 8 deletions e2e/service/StateProofService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ import { expect } from 'chai';
import { Observable } from 'rxjs';
import { take, toArray } from 'rxjs/operators';
import { Order, RepositoryFactoryHttp, SearchCriteria, SearcherRepository } from '../../src/infrastructure';
import { NamespaceRegistrationType } from '../../src/model/namespace';
import { StateMerkleProof } from '../../src/model/state';
import { StateProofService } from '../../src/service';

const repositoryFactory = new RepositoryFactoryHttp('http://api-01.us-west-2.0.10.0.x.symboldev.network:3000');
const url = 'http://api-01.us-west-2.0.10.0.x.symboldev.network:3000';
const repositoryFactory = new RepositoryFactoryHttp(url);
const service = new StateProofService(repositoryFactory);
const stateCounts = 50;
//Process the latest data first.
Expand All @@ -30,26 +32,26 @@ const order = Order.Desc;
// TODO, create dynamic it tests

async function test<E, C extends SearchCriteria>(
path: string,
repository: SearcherRepository<E, C>,
merkleMethod: (state: E) => Observable<StateMerkleProof>,
getId: (state: E) => string,
criteria: C = { order, pageSize: stateCounts } as C,
): Promise<void> {
const streamer = repository.streamer();
const infos = await streamer
.search({ order, pageSize: stateCounts } as C)
.pipe(take(stateCounts), toArray())
.toPromise();
const infos = await streamer.search(criteria).pipe(take(stateCounts), toArray()).toPromise();
const promises = infos.map(async (info) => {
const idText = getId(info);
const stateUrl = `${url}/${path}/${idText}`;
try {
const merkle = await merkleMethod(info).toPromise();
expect(merkle).to.not.undefined;
if (merkle.valid) console.log(idText + ' ' + merkle.valid);
if (merkle.valid) console.log(stateUrl + ' ' + merkle.valid);
else {
console.error(idText + ' ' + merkle.valid);
console.error(stateUrl + ' ' + merkle.valid);
}
} catch (e) {
console.error(idText + ' ' + e);
console.error(stateUrl + ' ' + e);
console.error(e);
}
});
Expand All @@ -59,6 +61,7 @@ async function test<E, C extends SearchCriteria>(
describe('StateProofService', () => {
it('Mosaics', async () => {
await test(
'mosaics',
repositoryFactory.createMosaicRepository(),
(info) => service.mosaic(info),
(info) => info.id.toHex(),
Expand All @@ -67,14 +70,17 @@ describe('StateProofService', () => {

it('Namespaces', async () => {
await test(
'namespaces',
repositoryFactory.createNamespaceRepository(),
(info) => service.namespaces(info),
(info) => info.id.toHex(),
{ order, pageSize: stateCounts, registrationType: NamespaceRegistrationType.RootNamespace },
);
});

it('Accounts', async () => {
await test(
'accounts',
repositoryFactory.createAccountRepository(),
(info) => service.account(info),
(info) => info.address.plain(),
Expand All @@ -83,6 +89,7 @@ describe('StateProofService', () => {

it('Hash Lock', async () => {
await test(
'lock/hash',
repositoryFactory.createHashLockRepository(),
(info) => service.hashLock(info),
(info) => info.hash,
Expand All @@ -91,6 +98,7 @@ describe('StateProofService', () => {

it('Secret Lock', async () => {
await test(
'lock/secret',
repositoryFactory.createSecretLockRepository(),
(info) => service.secretLock(info),
(info) => info.compositeHash,
Expand All @@ -99,6 +107,7 @@ describe('StateProofService', () => {

it('Account restrictions', async () => {
await test(
'restrictions/account',
repositoryFactory.createRestrictionAccountRepository(),
(info) => service.accountRestriction(info),
(info) => info.address.plain(),
Expand All @@ -107,6 +116,7 @@ describe('StateProofService', () => {

it('Mosaic restrictions', async () => {
await test(
'restrictions/mosaic',
repositoryFactory.createRestrictionMosaicRepository(),
(info) => service.mosaicRestriction(info),
(info) => info.compositeHash,
Expand All @@ -115,6 +125,7 @@ describe('StateProofService', () => {

it('Metadata', async () => {
await test(
'metadata',
repositoryFactory.createMetadataRepository(),
(info) => service.metadata(info),
(info) => info.metadataEntry.compositeHash,
Expand Down
18 changes: 17 additions & 1 deletion src/core/format/Convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ export class Convert {
/**
* Determines whether or not a string is a hex string.
* @param {string} input The string to test.
* @param {string} expectedSize the expected size of the input
* @returns {boolean} true if the input is a hex string, false otherwise.
*/
public static isHexString = (input: string): boolean => {
public static isHexString = (input: string, expectedSize = 0): boolean => {
if (0 !== input.length % 2) {
return false;
}
Expand All @@ -45,9 +46,24 @@ export class Convert {
return false;
}
}
if (expectedSize && expectedSize !== input.length) {
return false;
}
return true;
};

/**
* Validates if a string is a valid hex of the expected size.
* @param {string} input The string to test.
* @param {string} expectedSize the expected size of the input
* @param {string} message error message.
*/
public static validateHexString = (input: string, expectedSize: number, message: string): void => {
if (!Convert.isHexString(input, expectedSize)) {
throw new Error(`${message}. Value ${input} is not an hex string of size ${expectedSize}.`);
}
};

/**
* Converts a hex string to a uint8 array.
* @param {string} input A hex encoded string.
Expand Down
2 changes: 1 addition & 1 deletion src/infrastructure/AccountHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class AccountHttp extends Http implements AccountRepository {
*
* @param address the address
*/
getAccountsInfoMerkle(address: Address): Observable<MerkleStateInfo> {
getAccountInfoMerkle(address: Address): Observable<MerkleStateInfo> {
return this.call(this.accountRoutesApi.getAccountInfoMerkle(address.plain()), DtoMapping.toMerkleStateInfo);
}

Expand Down
2 changes: 1 addition & 1 deletion src/infrastructure/AccountRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ export interface AccountRepository extends SearcherRepository<AccountInfo, Accou
* @param address Address
* @returns Observable<MerkleStateInfo>
*/
getAccountsInfoMerkle(address: Address): Observable<MerkleStateInfo>;
getAccountInfoMerkle(address: Address): Observable<MerkleStateInfo>;
}
4 changes: 2 additions & 2 deletions src/infrastructure/RestrictionAccountRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import { Address } from '../model/account';
import { MerkleStateInfo } from '../model/blockchain';
import { AccountRestrictions } from '../model/restriction';
import { SearcherRepository } from './paginationStreamer';
import { RestrictionMosaicSearchCriteria } from './searchCriteria';
import { RestrictionAccountSearchCriteria } from './searchCriteria';

export interface RestrictionAccountRepository extends SearcherRepository<AccountRestrictions, RestrictionMosaicSearchCriteria> {
export interface RestrictionAccountRepository extends SearcherRepository<AccountRestrictions, RestrictionAccountSearchCriteria> {
/**
* Gets Account restrictions.
* @param address the address
Expand Down
Loading

0 comments on commit 52e81a5

Please sign in to comment.