Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
183 changes: 183 additions & 0 deletions e2e/infrastructure/TransactionHttp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {ChronoUnit} from 'js-joda';
import {keccak_256, sha3_256} from 'js-sha3';
import {Crypto} from '../../src/core/crypto';
import { Convert as convert } from '../../src/core/format';
import { TransactionMapping } from '../../src/core/utils/TransactionMapping';
import {AccountHttp} from '../../src/infrastructure/AccountHttp';
import { NamespaceHttp } from '../../src/infrastructure/infrastructure';
import {Listener} from '../../src/infrastructure/Listener';
Expand All @@ -31,6 +32,7 @@ import { Mosaic } from '../../src/model/mosaic/Mosaic';
import {MosaicId} from '../../src/model/mosaic/MosaicId';
import {MosaicNonce} from '../../src/model/mosaic/MosaicNonce';
import {MosaicProperties} from '../../src/model/mosaic/MosaicProperties';
import { MosaicRestrictionType } from '../../src/model/mosaic/MosaicRestrictionType';
import {MosaicSupplyType} from '../../src/model/mosaic/MosaicSupplyType';
import {NetworkCurrencyMosaic} from '../../src/model/mosaic/NetworkCurrencyMosaic';
import { AliasActionType } from '../../src/model/namespace/AliasActionType';
Expand All @@ -44,18 +46,22 @@ import { AccountRestrictionTransaction } from '../../src/model/transaction/Accou
import { AddressAliasTransaction } from '../../src/model/transaction/AddressAliasTransaction';
import {AggregateTransaction} from '../../src/model/transaction/AggregateTransaction';
import {CosignatureSignedTransaction} from '../../src/model/transaction/CosignatureSignedTransaction';
import { CosignatureTransaction } from '../../src/model/transaction/CosignatureTransaction';
import {Deadline} from '../../src/model/transaction/Deadline';
import { HashLockTransaction } from '../../src/model/transaction/HashLockTransaction';
import {HashType} from '../../src/model/transaction/HashType';
import { LinkAction } from '../../src/model/transaction/LinkAction';
import {LockFundsTransaction} from '../../src/model/transaction/LockFundsTransaction';
import { MosaicAddressRestrictionTransaction } from '../../src/model/transaction/MosaicAddressRestrictionTransaction';
import { MosaicAliasTransaction } from '../../src/model/transaction/MosaicAliasTransaction';
import {MosaicDefinitionTransaction} from '../../src/model/transaction/MosaicDefinitionTransaction';
import { MosaicGlobalRestrictionTransaction } from '../../src/model/transaction/MosaicGlobalRestrictionTransaction';
import {MosaicSupplyChangeTransaction} from '../../src/model/transaction/MosaicSupplyChangeTransaction';
import { PlainMessage } from '../../src/model/transaction/PlainMessage';
import {RegisterNamespaceTransaction} from '../../src/model/transaction/RegisterNamespaceTransaction';
import {SecretLockTransaction} from '../../src/model/transaction/SecretLockTransaction';
import {SecretProofTransaction} from '../../src/model/transaction/SecretProofTransaction';
import { SignedTransaction } from '../../src/model/transaction/SignedTransaction';
import {Transaction} from '../../src/model/transaction/Transaction';
import {TransactionType} from '../../src/model/transaction/TransactionType';
import {TransferTransaction} from '../../src/model/transaction/TransferTransaction';
Expand Down Expand Up @@ -117,6 +123,7 @@ describe('TransactionHttp', () => {
});
});
});

describe('MosaicDefinitionTransaction', () => {
let listener: Listener;
before (() => {
Expand All @@ -137,6 +144,7 @@ describe('TransactionHttp', () => {
supplyMutable: true,
transferable: true,
divisibility: 3,
restrictable: true,
duration: UInt64.fromUint(1000),
}),
NetworkType.MIJIN_TEST,
Expand All @@ -159,6 +167,7 @@ describe('TransactionHttp', () => {
transactionHttp.announce(signedTransaction);
});
});

describe('MosaicDefinitionTransaction', () => {
let listener: Listener;
before (() => {
Expand All @@ -178,6 +187,7 @@ describe('TransactionHttp', () => {
supplyMutable: true,
transferable: true,
divisibility: 3,
restrictable: true,
}),
NetworkType.MIJIN_TEST,
);
Expand All @@ -197,6 +207,118 @@ describe('TransactionHttp', () => {
transactionHttp.announce(signedTransaction);
});
});

describe('MosaicGlobalRestrictionTransaction', () => {
let listener: Listener;
before (() => {
listener = new Listener(config.apiUrl);
return listener.open();
});
after(() => {
return listener.close();
});

it('standalone', (done) => {
const mosaicGlobalRestrictionTransaction = MosaicGlobalRestrictionTransaction.create(
Deadline.create(),
mosaicId,
new MosaicId(UInt64.fromUint(0).toDTO()),
UInt64.fromUint(60641),
UInt64.fromUint(0),
MosaicRestrictionType.NONE,
UInt64.fromUint(0),
MosaicRestrictionType.GE,
NetworkType.MIJIN_TEST,
);
const signedTransaction = mosaicGlobalRestrictionTransaction.signWith(account, generationHash);

listener.confirmed(account.address).subscribe((transaction: Transaction) => {
done();
});
listener.status(account.address).subscribe((error) => {
console.log('Error:', error);
assert(false);
done();
});
transactionHttp.announce(signedTransaction);
});
});
describe('MosaicGlobalRestrictionTransaction', () => {
let listener: Listener;
before (() => {
listener = new Listener(config.apiUrl);
return listener.open();
});
after(() => {
return listener.close();
});
it('aggregate', (done) => {
const mosaicGlobalRestrictionTransaction = MosaicGlobalRestrictionTransaction.create(
Deadline.create(),
mosaicId,
new MosaicId(UInt64.fromUint(0).toDTO()),
UInt64.fromUint(60641),
UInt64.fromUint(0),
MosaicRestrictionType.GE,
UInt64.fromUint(1),
MosaicRestrictionType.GE,
NetworkType.MIJIN_TEST,
);
const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(),
[mosaicGlobalRestrictionTransaction.toAggregate(account.publicAccount)],
NetworkType.MIJIN_TEST,
[],
);
const signedTransaction = aggregateTransaction.signWith(account, generationHash);
listener.confirmed(account.address).subscribe((transaction: Transaction) => {
done();
});
listener.status(account.address).subscribe((error) => {
console.log('Error:', error);
assert(false);
done();
});
transactionHttp.announce(signedTransaction);
});
});

describe('MosaicAddressRestrictionTransaction', () => {
let listener: Listener;
before (() => {
listener = new Listener(config.apiUrl);
return listener.open();
});
after(() => {
return listener.close();
});
it('aggregate', (done) => {
const mosaicAddressRestrictionTransaction = MosaicAddressRestrictionTransaction.create(
Deadline.create(),
mosaicId,
UInt64.fromUint(60641),
account3.address,
UInt64.fromHex('FFFFFFFFFFFFFFFF'),
UInt64.fromUint(2),
NetworkType.MIJIN_TEST,
);
const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(),
[mosaicAddressRestrictionTransaction.toAggregate(account.publicAccount)],
NetworkType.MIJIN_TEST,
[],
);
const signedTransaction = aggregateTransaction.signWith(account, generationHash);
listener.confirmed(account.address).subscribe((transaction: Transaction) => {
done();
});
listener.status(account.address).subscribe((error) => {
console.log('Error:', error);
assert(false);
done();
});
transactionHttp.announce(signedTransaction);
});
});

describe('TransferTransaction', () => {
let listener: Listener;
before (() => {
Expand Down Expand Up @@ -1641,6 +1763,67 @@ describe('TransactionHttp', () => {
});
});

describe('SignTransactionGivenSignatures', () => {
let listener: Listener;
before (() => {
listener = new Listener(config.apiUrl);
return listener.open();
});
after(() => {
return listener.close();
});
it('Announce cosign signatures given', (done) => {

/**
* @see https://github.com/nemtech/nem2-sdk-typescript-javascript/issues/112
*/
// AliceAccount: account
// BobAccount: account

const sendAmount = NetworkCurrencyMosaic.createRelative(1000);
const backAmount = NetworkCurrencyMosaic.createRelative(1);

const aliceTransferTransaction = TransferTransaction.create(Deadline.create(), account2.address, [sendAmount],
PlainMessage.create('payout'), NetworkType.MIJIN_TEST);
const bobTransferTransaction = TransferTransaction.create(Deadline.create(), account.address, [backAmount],
PlainMessage.create('payout'), NetworkType.MIJIN_TEST);

// 01. Alice creates the aggregated tx and sign it. Then payload send to Bob
const aggregateTransaction = AggregateTransaction.createComplete(
Deadline.create(),
[
aliceTransferTransaction.toAggregate(account.publicAccount),
bobTransferTransaction.toAggregate(account2.publicAccount),
],
NetworkType.MIJIN_TEST,
[],
);

const aliceSignedTransaction = aggregateTransaction.signWith(account, generationHash);

// 02 Bob cosigns the tx and sends it back to Alice
const signedTxBob = CosignatureTransaction.signTransactionPayload(account2, aliceSignedTransaction.payload, generationHash);

// 03. Alice collects the cosignatures, recreate, sign, and announces the transaction
const cosignatureSignedTransactions = [
new CosignatureSignedTransaction(signedTxBob.parentHash, signedTxBob.signature, signedTxBob.signer),
];
const recreatedTx = TransactionMapping.createFromPayload(aliceSignedTransaction.payload) as AggregateTransaction;

const signedTransaction = recreatedTx.signTransactionGivenSignatures(account, cosignatureSignedTransactions, generationHash);

listener.confirmed(account.address).subscribe(() => {
done();
});
listener.status(account.address).subscribe((error) => {
console.log('Error:', error);
assert(false);
done();
});
transactionHttp.announce(signedTransaction);
});
});

describe('transactions', () => {
it('should call transactions successfully', (done) => {
accountHttp.transactions(account.publicAccount).subscribe((transactions) => {
Expand Down
Loading