Skip to content

Commit 84311ff

Browse files
authored
Merge pull request #18 from Golem-Base/rvdp/dev
fix: make sure entity keys parsed from tx receipts are always 32 bytes
2 parents 96c9244 + 3be4634 commit 84311ff

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

src/client.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ export async function createClient(
299299
return {
300300
...receipts,
301301
createEntitiesReceipts: receipts.createEntitiesReceipts.concat([{
302-
entityKey: toHex(parsed.args.entityKey),
302+
entityKey: toHex(parsed.args.entityKey, { size: 32 }),
303303
expirationBlock: Number(parsed.args.expirationBlock),
304304
}]),
305305
}
@@ -308,7 +308,7 @@ export async function createClient(
308308
return {
309309
...receipts,
310310
updateEntitiesReceipts: receipts.updateEntitiesReceipts.concat([{
311-
entityKey: toHex(parsed.args.entityKey),
311+
entityKey: toHex(parsed.args.entityKey, { size: 32 }),
312312
expirationBlock: Number(parsed.args.expirationBlock),
313313
}]),
314314
}
@@ -317,7 +317,7 @@ export async function createClient(
317317
return {
318318
...receipts,
319319
extendEntitiesReceipts: receipts.extendEntitiesReceipts.concat([{
320-
entityKey: toHex(parsed.args.entityKey),
320+
entityKey: toHex(parsed.args.entityKey, { size: 32 }),
321321
newExpirationBlock: Number(parsed.args.newExpirationBlock),
322322
oldExpirationBlock: Number(parsed.args.oldExpirationBlock),
323323
}]),
@@ -327,7 +327,7 @@ export async function createClient(
327327
return {
328328
...receipts,
329329
deleteEntitiesReceipts: receipts.deleteEntitiesReceipts.concat([{
330-
entityKey: toHex(parsed.args.entityKey),
330+
entityKey: toHex(parsed.args.entityKey, { size: 32 }),
331331
}]),
332332
}
333333
}

test/internal/client.spec.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ import {
1515
Annotation,
1616
Tagged,
1717
type AccountData,
18+
golemBaseABI,
1819
} from "../../src/index.ts"
1920
import {
2021
generateRandomBytes,
2122
generateRandomString,
2223
} from "../utils.ts"
2324
import { GolemBaseClient } from '../../src/internal/client.ts'
25+
import { decodeEventLog, toHex } from 'viem'
2426

2527
const log = new Logger<ILogObj>({
2628
type: "pretty",
@@ -146,13 +148,26 @@ describe("the internal golem-base client", () => {
146148
numericAnnotations: [new Annotation("ix", 3)]
147149
}
148150
]
149-
const receipts = await client.walletClient.sendGolemBaseTransactionAndWaitForReceipt(creates)
151+
const receipt = await client.walletClient.sendGolemBaseTransactionAndWaitForReceipt(creates)
150152
entitiesOwnedCount += creates.length;
151-
// Save this key for later
152-
[{ entityKey, expirationBlock }] = receipts.logs.map(txlog => ({
153-
entityKey: txlog.topics[1] as Hex,
154-
expirationBlock: parseInt(txlog.data),
155-
}))
153+
154+
const txlog = receipt.logs[0]
155+
const parsed = decodeEventLog({
156+
abi: golemBaseABI,
157+
data: txlog.data,
158+
topics: txlog.topics
159+
})
160+
161+
expect(parsed.eventName).to.eql("GolemBaseStorageEntityCreated")
162+
163+
if (parsed.eventName === "GolemBaseStorageEntityCreated") {
164+
// Save these for later
165+
entityKey = toHex(parsed.args.entityKey, { size: 32 })
166+
expirationBlock = Number(parsed.args.expirationBlock)
167+
}
168+
169+
expect(entityKey).to.exist
170+
expect(expirationBlock).to.exist
156171

157172
expect(await numOfEntitiesOwned(client)).to.eql(entitiesOwnedCount)
158173
})

0 commit comments

Comments
 (0)