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

Fix Transaction Default Values #1730

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
10 changes: 8 additions & 2 deletions src/chains/ethereum/transaction/src/runtime-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,14 @@ export abstract class RuntimeTransaction extends BaseTransaction {
data.to == null
? RPCQUANTITY_EMPTY
: toValidLengthAddress(data.to, "to");
this.value = Quantity.from(data.value);
this.data = Data.from(data.data == null ? data.input : data.data);
this.value = Quantity.from(data.value || 0);
const dataVal =
data.data == null
? data.input == null
? "0x"
: data.input
: data.data;
this.data = Data.from(dataVal);
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/chains/ethereum/transaction/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,13 @@ describe("@ganache/ethereum-transaction", async () => {
assert.strictEqual(jsonTx.from, tx.from);
assert.strictEqual(jsonTx.to, tx.to);
assert.strictEqual(jsonTx.value, tx.value);
// when this value is omitted, we set a default
assert.strictEqual(jsonTx.value.toString(), "0x0");
assert.strictEqual(jsonTx.gas, tx.gas);
assert.strictEqual(jsonTx.gasPrice, tx.gasPrice);
assert.strictEqual(jsonTx.input, tx.data);
// when this value is omitted, we set a default
assert.strictEqual(jsonTx.input.toString(), "0x");
assert.strictEqual(jsonTx.v, tx.v);
assert.strictEqual(jsonTx.r, tx.r);
assert.strictEqual(jsonTx.s, tx.s);
Expand Down Expand Up @@ -398,9 +402,13 @@ describe("@ganache/ethereum-transaction", async () => {
assert.strictEqual(jsonTx.from, tx.from);
assert.strictEqual(jsonTx.to, tx.to);
assert.strictEqual(jsonTx.value, tx.value);
// when this value is omitted, we set a default
assert.strictEqual(jsonTx.value.toString(), "0x0");
assert.strictEqual(jsonTx.gas, tx.gas);
assert.strictEqual(jsonTx.gasPrice, tx.gasPrice);
assert.strictEqual(jsonTx.input, tx.data);
// when this value is omitted, we set a default
assert.strictEqual(jsonTx.input.toString(), "0x");
assert.strictEqual(jsonTx.v, tx.v);
assert.strictEqual(jsonTx.r, tx.r);
assert.strictEqual(jsonTx.s, tx.s);
Expand Down Expand Up @@ -473,11 +481,15 @@ describe("@ganache/ethereum-transaction", async () => {
assert.strictEqual(jsonTx.from, tx.from);
assert.strictEqual(jsonTx.to, tx.to);
assert.strictEqual(jsonTx.value, tx.value);
// when this value is omitted, we set a default
assert.strictEqual(jsonTx.value.toString(), "0x0");
assert.strictEqual(jsonTx.gas, tx.gas);
assert.strictEqual(jsonTx.maxPriorityFeePerGas, tx.maxPriorityFeePerGas);
assert.strictEqual(jsonTx.maxFeePerGas, tx.maxFeePerGas);
assert.strictEqual(jsonTx.gasPrice, tx.effectiveGasPrice);
assert.strictEqual(jsonTx.input, tx.data);
// when this value is omitted, we set a default
assert.strictEqual(jsonTx.input.toString(), "0x");
assert.strictEqual(jsonTx.v, tx.v);
assert.strictEqual(jsonTx.r, tx.r);
assert.strictEqual(jsonTx.s, tx.s);
Expand Down