Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.
Prev Previous commit
Next Next commit
Memoize options and add and update some tests
  • Loading branch information
eggplantzzz committed Feb 16, 2021
commit 53b81127204916a4c5eeb2b57d57d09ad385ad01
11 changes: 7 additions & 4 deletions src/chains/ethereum/ethereum/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1201,16 +1201,19 @@ export default class EthereumApi implements types.Api {
]);
if (transaction) {
return receipt.toJSON(block, transaction);
} else if (
this.#options.miner.blockTime <= 0 &&
this.#options.miner.legacyInstamine !== true &&
}

const options = this.#options;
if (
options.miner.blockTime <= 0 &&
options.miner.legacyInstamine !== true &&
this.#blockchain.isStarted()
) {
// if we are performing non-legacy instamining, then check to see if the
// transaction is pending so as to warn about the v7 breaking change
const tx = this.#blockchain.transactions.transactionPool.find(txHash);
if (tx != null) {
this.#options.logging.logger.log(
options.logging.logger.log(
" > Ganache `eth_getTransactionReceipt` notice: the transaction with hash\n" +
` > \`${txHash.toString()}\` has not\n` +
" > yet been mined. See https://trfl.co/v7-instamine for additional information."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe("api", () => {
describe("eth", () => {
describe("getTransactionReceipt", () => {
let provider: EthereumProvider;
let logger;
let logger, from;

beforeEach(async () => {
// create a logger to test output
Expand All @@ -22,21 +22,18 @@ describe("api", () => {
}
};
provider = await getProvider({ logging: { logger } });
[from] = await provider.send("eth_accounts");
});

afterEach(() => {
logger.clearLoggedStuff();
});

it("returns the receipt for the transaction", async () => {
const [from] = await provider.send("eth_accounts");
await provider.send("eth_subscribe", ["newHeads"]);

const hash = await provider.send("eth_sendTransaction", [
{
from,
to: from
}
{ from, to: from }
]);

// wait for the tx to be mined
Expand Down Expand Up @@ -66,13 +63,8 @@ describe("api", () => {

describe("legacy instamine detection and notice", () => {
it("logs a warning if the transaction hasn't been mined yet", async () => {
const [from] = await provider.send("eth_accounts");

const hash = await provider.send("eth_sendTransaction", [
{
from,
to: from
}
{ from, to: from }
]);

// do not wait for the tx to be mined which will create a warning
Expand All @@ -94,16 +86,10 @@ describe("api", () => {
miner: { blockTime: 1 }
});

const [from] = await nonInstamineProvider.send("eth_accounts");

const hash = await nonInstamineProvider.send("eth_sendTransaction", [
{
from,
to: from
}
{ from, to: from }
]);

// do not wait for the tx to be mined which will create a warning
const result = await nonInstamineProvider.send(
"eth_getTransactionReceipt",
[hash]
Expand All @@ -116,6 +102,50 @@ describe("api", () => {
)
);
});

it("doesn't log the notice when the chain is stopped", async () => {
await provider.send("miner_stop", []);
const hash = await provider.send("eth_sendTransaction", [
{ from, to: from }
]);

const result = await provider.send("eth_getTransactionReceipt", [
hash
]);

assert.strictEqual(result, null);
assert(
!logger.loggedStuff.includes(
"Ganache `eth_getTransactionReceipt` notice"
)
);
});

it("doesn't log if legacyInstamine is enabled", async () => {
const legacyInstamineProvider = await getProvider({
logging: { logger },
miner: { legacyInstamine: true }
});

const hash = await legacyInstamineProvider.send(
"eth_sendTransaction",
[{ from, to: from }]
);

const result = await legacyInstamineProvider.send(
"eth_getTransactionReceipt",
[hash]
);

// the tx is mined before sending the tx hash back to the user
// if legacyInstamine is enabled - so they will get a receipt
assert(result);
assert(
!logger.loggedStuff.includes(
"Ganache `eth_getTransactionReceipt` notice"
)
);
});
});
});
});
Expand Down