Skip to content

Commit

Permalink
fix: sendRawTransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisCarriere committed Jun 12, 2023
1 parent 402b4ac commit 66be776
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@enf/eos-evm-miner",
"version": "0.3.1",
"version": "0.3.2",
"description": "EOS EVM miner",
"type": "module",
"exports": "./dist/index.js",
Expand Down
18 changes: 11 additions & 7 deletions src/eth_sendRawTransaction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ const session = createSession({
privateKey: PrivateKey.generate("K1").toString(),
})

const rplxs = [
["0xf9016d3a8534630b8a008302a56d941c8f68e8adbd75c23281e5c88e44d0b7023a423880b9010418cbafe5000000000000000000000000000000000000000000000000000000000004eb860000000000000000000000000000000000000000000000000696461c6fd44b5400000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000b6bd7e6222b524c2d3bdd7eccb198ccfbc5880a00000000000000000000000000000000000000000000000000000000648783570000000000000000000000000000000000000000000000000000000000000002000000000000000000000000fa9343c3897324496a05fc75abed6bac29f8a40f000000000000000000000000c00592aa41d32d137dc480d9f6d0df19b860104f828b06a014778f2186e66ce06c656c1c8233628e51e5da28c26ff2bf919bc188acadf5cba030c57201adef3c9305b9ecf48ed3433c62e145b74e2da3a58ef0396a368c401d","0x4fe79b3a1e9f7b120399c05fca41dda1cae8412caa1d081e37217d1c2f9e42af"],
["0xf9015682042c8522ecb25c0083033450941c8f68e8adbd75c23281e5c88e44d0b7023a4238881b1f9ca5fb325000b8e47ff36ab5000000000000000000000000000000000000000000000000000000000013d1a6000000000000000000000000000000000000000000000000000000000000008000000000000000000000000058836a592b25659733ecee0dbe313807f13cd45100000000000000000000000000000000000000000000000000000000648783e20000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c00592aa41d32d137dc480d9f6d0df19b860104f000000000000000000000000765277eebeca2e31912c9946eae1021199b39c61828b05a0de31deca0d4a21353cfc9320e719fe90553cfa5ddb65739579747044521a46aaa05ae417b2411079269e441ac449ce47d780bf98f7f6392725805f95df6e9f5c1d", "0x99f315915ce41fb2446fd300662ff00368e558edca67461659e29fdb64eede23"],
["f9015682042c8522ecb25c0083033450941c8f68e8adbd75c23281e5c88e44d0b7023a4238881b1f9ca5fb325000b8e47ff36ab5000000000000000000000000000000000000000000000000000000000013d1a6000000000000000000000000000000000000000000000000000000000000008000000000000000000000000058836a592b25659733ecee0dbe313807f13cd45100000000000000000000000000000000000000000000000000000000648783e20000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c00592aa41d32d137dc480d9f6d0df19b860104f000000000000000000000000765277eebeca2e31912c9946eae1021199b39c61828b05a0de31deca0d4a21353cfc9320e719fe90553cfa5ddb65739579747044521a46aaa05ae417b2411079269e441ac449ce47d780bf98f7f6392725805f95df6e9f5c1d", "0x99f315915ce41fb2446fd300662ff00368e558edca67461659e29fdb64eede23"]
]

test('eth_sendRawTransaction', async () => {
const params = [
// some fake tx from chatgpt, probably sends nukes
"0xf8aa8204e3843b9aca0082520894775e97edc8f2a2c7aa290d372320d56d1c9e19b80b844a9059cbb000000000000000000000000a7a0a0a0000000000000000000000000000000000000000000000000000000000001ba0aa0721dc8f0b44f7a7dfb5f5d5a15d5c5c5f5e5d5d5c5b5b5a5a5b5c5d5e5f5c5c5d5e5f5e5d5c5b5a5b5b5a5a5b5c5d5e5f5c5c5d5e5f5e5d5c5b5a5b5a5a5b",
"latest"
]
const trx_id = await eth_sendRawTransaction(session, params, false);
assert.equal(trx_id, '0x262d98979f48d17906590502f99697e864933df08cc79c34c785ed34aadadd8b', 'Expected gas price have been gotten from an API');
for ( const [rlptx, expected] of rplxs ) {
const params = [ rlptx, "latest" ];
const trx_id = await eth_sendRawTransaction(session, params, false);
assert.equal(trx_id, expected);
}
});
4 changes: 2 additions & 2 deletions src/eth_sendRawTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { logger } from "./logger.js";
import { keccak256 } from "@ethereumjs/devp2p";

export async function eth_sendRawTransaction(session: Session, params: any[], broadcast = true) {
const rlptx = params[0].substr(2);
const rlptx = params[0].replace(/^0x/, "");
const action = pushtx(session, rlptx);
if ( broadcast ) {
const transact = await session.transact({action}, {broadcast});
Expand All @@ -15,5 +15,5 @@ export async function eth_sendRawTransaction(session: Session, params: any[], br
throw new Error("no response from Nodeos RPC endpoint");
}
}
return "0x" + keccak256(Buffer.from(rlptx)).toString("hex");
return `0x${ keccak256(Buffer.from(rlptx, "hex")).toString("hex") }`;
}

0 comments on commit 66be776

Please sign in to comment.