Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
popenta committed Dec 22, 2023
1 parent 2af440b commit 43cd1b3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
9 changes: 5 additions & 4 deletions src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ export class Transaction {
receiver: Address.fromBech32(transaction.receiver),
gasLimit: new BigNumber(transaction.gasLimit).toNumber(),
chainID: transaction.chainID,
value: transaction.value,
value: new BigNumber(transaction.value).toFixed(0),
data: new TransactionPayload(Buffer.from(transaction.data)),
nonce: Number(transaction.nonce),
gasPrice: Number(transaction.gasPrice),
Expand Down Expand Up @@ -677,15 +677,16 @@ export class TransactionComputer {
const tx = Transaction.fromTransactionNext(transaction);
let buffer = serializer.serializeTransaction(tx);
let hash = createTransactionHasher(TRANSACTION_HASH_LENGTH)
.update(buffer);
.update(buffer)
.digest("hex");

return hash;
return new Uint8Array(Buffer.from(hash, "hex"));
}

private toPlainObject(transaction: ITransactionNext) {
return {
nonce: Number(transaction.nonce),
value: transaction.value.toString(),
value: new BigNumber(transaction.value).toFixed(0),
receiver: transaction.receiver,
sender: transaction.sender,
senderUsername: transaction.senderUsername ? Buffer.from(transaction.senderUsername).toString("base64") : undefined,
Expand Down
18 changes: 12 additions & 6 deletions src/transactionNext.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,11 @@ describe("test transaction next", async () => {
"hex"
);

const hash: any = transactionComputer.computeTransactionHash(transaction);
assert.equal(hash.digest("hex"), "169b76b752b220a76a93aeebc462a1192db1dc2ec9d17e6b4d7b0dcc91792f03");
const hash = transactionComputer.computeTransactionHash(transaction);
assert.equal(
Buffer.from(hash).toString("hex"),
"169b76b752b220a76a93aeebc462a1192db1dc2ec9d17e6b4d7b0dcc91792f03"
);
});

it("should compute transaction hash with usernames", async () => {
Expand All @@ -131,8 +134,11 @@ describe("test transaction next", async () => {
"hex"
);

const hash: any = transactionComputer.computeTransactionHash(transaction);
assert.equal(hash.digest("hex"), "41b5acf7ebaf4a9165a64206b6ebc02021b3adda55ffb2a2698aac2e7004dc29");
const hash = transactionComputer.computeTransactionHash(transaction);
assert.equal(
Buffer.from(hash).toString("hex"),
"41b5acf7ebaf4a9165a64206b6ebc02021b3adda55ffb2a2698aac2e7004dc29"
);
});

it("should throw `NotEnoughGas` error", async () => {
Expand Down Expand Up @@ -178,7 +184,7 @@ describe("test transaction next", async () => {
assert.equal(gasLimit.toString(), "6005000");
});

it.only("should compute guarded transaction", async () => {
it("should compute guarded transaction", async () => {
const alice = wallets.alice;

const transaction = new TransactionNext({
Expand All @@ -187,7 +193,7 @@ describe("test transaction next", async () => {
receiver: wallets.bob.address.bech32(),
gasLimit: 150000,
gasPrice: 1000000000,
data: Buffer.from("test data field"),
data: new Uint8Array(Buffer.from("test data field")),
version: 2,
options: 2,
nonce: 92,
Expand Down

0 comments on commit 43cd1b3

Please sign in to comment.