Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
fix: ensure eth_sendTransaction returns the correct error when the …
Browse files Browse the repository at this point in the history
…account has insufficient funds (#1661)
  • Loading branch information
davidmurdoch committed Dec 3, 2021
1 parent 9c76a8b commit f06c034
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
24 changes: 24 additions & 0 deletions src/chains/ethereum/ethereum/tests/api/eth/sendTransaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,30 @@ describe("api", () => {
});
});

describe("insufficient funds", () => {
it("returns an error when account has insufficient funds to send the transaction", async () => {
const p = await getProvider({
miner: { legacyInstamine: true },
chain: { vmErrorsOnRPCResponse: true }
});
const [from, to] = await p.send("eth_accounts");
const balance = await p.send("eth_getBalance", [from]);
const types = ["0x0", "0x1", "0x2"] as const;
for (let i = 0; i < types.length; i++) {
await assert.rejects(
p.send("eth_sendTransaction", [
{ type: types[i], from, to, value: balance }
]),
new RegExp(
`VM Exception while processing transaction: sender doesn't have enough funds to send tx\\. The upfront cost is: \\d+ and the sender's account \\(${from}\\) only has: ${BigInt(
balance
)} \\(vm hf=london -> block -> tx\\)`
)
);
}
});
});

describe("contracts", () => {
const contractDir = join(__dirname, "contracts");
describe("out of gas", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ export class EIP1559FeeMarketTransaction extends RuntimeTransaction {
}

public toVmTransaction() {
const sender = this.from.toBuffer();
const from = this.from;
const sender = from.toBuffer();
const to = this.to.toBuffer();
const data = this.data.toBuffer();
return {
Expand All @@ -169,7 +170,10 @@ export class EIP1559FeeMarketTransaction extends RuntimeTransaction {
AccessListJSON: this.accessListJSON,
getSenderAddress: () => ({
buf: sender,
equals: (a: { buf: Buffer }) => sender.equals(a.buf)
equals: (a: { buf: Buffer }) => sender.equals(a.buf),
toString() {
return from.toString();
}
}),
/**
* the minimum amount of gas the tx must have (DataFee + TxFee + Creation Fee)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export class EIP2930AccessListTransaction extends RuntimeTransaction {
}

public toVmTransaction() {
const from = this.from;
const sender = this.from.toBuffer();
const to = this.to.toBuffer();
const data = this.data.toBuffer();
Expand All @@ -170,7 +171,10 @@ export class EIP2930AccessListTransaction extends RuntimeTransaction {
AccessListJSON: this.accessListJSON,
getSenderAddress: () => ({
buf: sender,
equals: (a: { buf: Buffer }) => sender.equals(a.buf)
equals: (a: { buf: Buffer }) => sender.equals(a.buf),
toString() {
return from.toString();
}
}),
/**
* the minimum amount of gas the tx must have (DataFee + TxFee + Creation Fee)
Expand Down
8 changes: 6 additions & 2 deletions src/chains/ethereum/transaction/src/legacy-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ export class LegacyTransaction extends RuntimeTransaction {
return new LegacyTransaction(data, common);
}
public toVmTransaction() {
const sender = this.from.toBuffer();
const from = this.from;
const sender = from.toBuffer();
const to = this.to.toBuffer();
const data = this.data.toBuffer();
return {
Expand All @@ -131,7 +132,10 @@ export class LegacyTransaction extends RuntimeTransaction {
data,
getSenderAddress: () => ({
buf: sender,
equals: (a: { buf: Buffer }) => sender.equals(a.buf)
equals: (a: { buf: Buffer }) => sender.equals(a.buf),
toString() {
return from.toString();
}
}),
/**
* the minimum amount of gas the tx must have (DataFee + TxFee + Creation Fee)
Expand Down

0 comments on commit f06c034

Please sign in to comment.