Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
acb6e90
test: 1st commit getTransactionsForForging tests
air1one May 29, 2019
25ade7e
test: extend TransactionFactory to build customized payloads
spkjp Jun 1, 2019
b82deee
test: add types to delegates
spkjp Jun 1, 2019
a85bb3e
test: turn getTransactionsForForging tests into unit tests
spkjp Jun 1, 2019
1e7a220
test: tweak TransactionFactory
spkjp Jun 1, 2019
ddfb527
test: restore all commented tests
spkjp Jun 1, 2019
e1bbc83
test: add log for debugging
spkjp Jun 1, 2019
e70efe6
test: disable verifier mock
spkjp Jun 1, 2019
684f346
test: delete obsolete file
spkjp Jun 1, 2019
11182a5
Merge branch 'develop' into test/tx-pool-getTransactionsForForging
spkjp Jun 4, 2019
e84037b
fix(core-transaction-pool): remove already forged transactions before…
alessiodf Jun 2, 2019
709dc02
refactor(core-transaction-pool): extract into function
spkjp Jun 4, 2019
b07f824
test: make function async
spkjp Jun 4, 2019
fd5fd00
test: malformed serialized bytes tests
air1one Jun 4, 2019
b329a7a
Merge remote-tracking branch 'origin/develop' into test/tx-pool-getTr…
spkjp Jun 4, 2019
edff99d
test: spy on fromBytes and canBeApplied
spkjp Jun 4, 2019
9e9bae2
fix(crypto): throw if bytes are remaining after reading signatures
spkjp Jun 4, 2019
673e441
test: implement most todos
spkjp Jun 4, 2019
0c80ade
test: spy on removeForgedTransactions
spkjp Jun 4, 2019
16e26d4
misc: remove console.log
spkjp Jun 4, 2019
e868c36
Merge remote-tracking branch 'origin/develop' into test/tx-pool-getTr…
spkjp Jun 4, 2019
6af7a43
test: cast to number
spkjp Jun 5, 2019
d91484e
test: cleanup
spkjp Jun 5, 2019
a6021dd
test: use customSerialize
spkjp Jun 5, 2019
ed6692f
Merge remote-tracking branch 'origin/develop' into test/tx-pool-getTr…
spkjp Jun 5, 2019
85b1c94
test: update remaining todo
spkjp Jun 5, 2019
f956d7e
refactor: apply same checks in `loadAll`
spkjp Jun 5, 2019
4a1c952
test: remove todo
spkjp Jun 5, 2019
03c82f0
test(core-transaction-pool): index wallet with sufficient balance
Jun 5, 2019
eaed5ba
refactor: move to `getTransactionsData`
spkjp Jun 5, 2019
5afbf3b
refactor: rename
spkjp Jun 5, 2019
bb987e2
test: make async
spkjp Jun 5, 2019
e14c288
test(core-blockchain): add missing await
Jun 5, 2019
9957dbf
test(core-transaction-pool): add missing await
spkjp Jun 5, 2019
8cfb5c4
test(core-transaction-pool): missing await
spkjp Jun 5, 2019
d6091b4
test(core-transaction-pool): make it green
spkjp Jun 5, 2019
451e06b
test(core-blockchain): fix insufficient balance
spkjp Jun 5, 2019
073c6ef
test(core-blockchain): dont reindex pool wallet
spkjp Jun 5, 2019
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
1 change: 0 additions & 1 deletion __tests__/helpers/transaction-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ export class TransactionFactory {
Managers.configManager.setFromPreset(this.network);

const transactions: T[] = [];

for (let i = 0; i < quantity; i++) {
if (this.builder.constructor.name === "TransferBuilder") {
// @FIXME: when we use any of the "withPassphrase*" methods the builder will
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,8 @@ describe("API 2.0 - Transactions", () => {
it.each([3, 5, 8])("should accept and broadcast %i transactions emptying a wallet", async txNumber => {
const sender = delegates[txNumber]; // use txNumber so that we use a different delegate for each test case
const receivers = generateWallets("testnet", 2);
const amountPlusFee = Math.floor(sender.balance / txNumber);
const lastAmountPlusFee = sender.balance - (txNumber - 1) * amountPlusFee;
const amountPlusFee = Math.floor(+sender.balance / txNumber);
const lastAmountPlusFee = +sender.balance - (txNumber - 1) * amountPlusFee;

const transactions = TransactionFactory.transfer(receivers[0].address, amountPlusFee - transferFee)
.withNetwork("testnet")
Expand Down Expand Up @@ -591,8 +591,8 @@ describe("API 2.0 - Transactions", () => {
async txNumber => {
const sender = delegates[txNumber + 1]; // use txNumber + 1 so that we don't use the same delegates as the above test
const receivers = generateWallets("testnet", 2);
const amountPlusFee = Math.floor(sender.balance / txNumber);
const lastAmountPlusFee = sender.balance - (txNumber - 1) * amountPlusFee + 1;
const amountPlusFee = Math.floor(+sender.balance / txNumber);
const lastAmountPlusFee = +sender.balance - (txNumber - 1) * amountPlusFee + 1;

const transactions = TransactionFactory.transfer(receivers[0].address, amountPlusFee - transferFee)
.withNetwork("testnet")
Expand Down
30 changes: 22 additions & 8 deletions __tests__/integration/core-blockchain/blockchain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ const addBlocks = async untilHeight => {
}
};

const indexWalletWithSufficientBalance = (transaction: Interfaces.ITransaction): void => {
const walletManager = blockchain.database.walletManager;

const wallet = walletManager.findByPublicKey(transaction.data.senderPublicKey);
wallet.balance = wallet.balance.abs().plus(transaction.data.amount.plus(transaction.data.fee));
walletManager.reindex(wallet);
};

describe("Blockchain", () => {
beforeAll(async () => {
container = await setUp();
Expand Down Expand Up @@ -91,19 +99,25 @@ describe("Blockchain", () => {

describe("postTransactions", () => {
it("should be ok", async () => {
const transactionsWithoutType2 = genesisBlock.transactions.filter(tx => tx.type !== 2);

blockchain.transactionPool.flush();
await blockchain.postTransactions(transactionsWithoutType2);
const transactions = blockchain.transactionPool.getTransactions(0, 200);

expect(transactions.length).toBe(transactionsWithoutType2.length);
jest.spyOn(blockchain.transactionPool as any, "removeForgedTransactions").mockReturnValue([]);

expect(transactions).toIncludeAllMembers(
transactionsWithoutType2.map(transaction => transaction.serialized),
);
for (const transaction of genesisBlock.transactions) {
indexWalletWithSufficientBalance(transaction);
}

const transferTransactions = genesisBlock.transactions.filter(tx => tx.type === 0);

await blockchain.postTransactions(transferTransactions);
const transactions = await blockchain.transactionPool.getTransactions(0, 200);

expect(transactions.length).toBe(transferTransactions.length);

expect(transactions).toIncludeAllMembers(transferTransactions.map(transaction => transaction.serialized));

blockchain.transactionPool.flush();
jest.restoreAllMocks();
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ jest.mock("../../../../../../../packages/core-p2p/src/socket-server/utils/valida

describe("Internal handlers - transactions", () => {
describe("getUnconfirmedTransactions", () => {
it("should return unconfirmed transactions", () => {
it("should return unconfirmed transactions", async () => {
transactionPool.getTransactionsForForging = jest.fn().mockReturnValue(["111"]);
transactionPool.getPoolSize = jest.fn().mockReturnValue(1);

expect(getUnconfirmedTransactions()).toEqual({ poolSize: 1, transactions: ["111"] });
expect(await getUnconfirmedTransactions()).toEqual({ poolSize: 1, transactions: ["111"] });
});
});
});
10 changes: 3 additions & 7 deletions __tests__/unit/core-transaction-pool/__stubs__/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,19 @@ export class Connection implements TransactionPool.IConnection {
return;
}

public getTransactionsForForging(blockSize: number): string[] {
public async getTransactionsForForging(blockSize: number): Promise<string[]> {
return [];
}

public getTransaction(id: string): Interfaces.ITransaction {
return undefined;
}

public getTransactions(start: number, size: number, maxBytes?: number): Buffer[] {
public async getTransactions(start: number, size: number, maxBytes?: number): Promise<Buffer[]> {
return [];
}

public getTransactionIdsForForging(start: number, size: number): string[] {
return undefined;
}

public getTransactionsData(start: number, size: number, maxBytes?: number): Interfaces.ITransaction[] {
public async getTransactionIdsForForging(start: number, size: number): Promise<string[]> {
return undefined;
}

Expand Down
Loading