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

fix: ensure eth_sendTransaction returns the correct error when the account has insufficient funds #1661

Merged
merged 2 commits into from
Dec 3, 2021
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
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