Skip to content

Commit

Permalink
Merge branch 'develop' into docs/24-log
Browse files Browse the repository at this point in the history
  • Loading branch information
faustbrian authored Jun 5, 2019
2 parents 72a04af + 974d28c commit 2dbcc32
Show file tree
Hide file tree
Showing 51 changed files with 933 additions and 337 deletions.
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

0 comments on commit 2dbcc32

Please sign in to comment.