Skip to content

Commit

Permalink
Fix decode of empty rule data v2 to work for constructing legacy spac…
Browse files Browse the repository at this point in the history
…es in harmony tests (#1220)
  • Loading branch information
clemire authored Oct 4, 2024
1 parent f6ee779 commit 1ea5ba0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/web3/src/entitlement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
decodeERC1155Params,
createOperationsTree,
XchainConfig,
EncodedNoopRuleData,
} from './entitlement'
import { MOCK_ADDRESS, MOCK_ADDRESS_2, MOCK_ADDRESS_3 } from './Utils'
import { zeroAddress } from 'viem'
Expand Down Expand Up @@ -989,6 +990,13 @@ test('encode/decode rule data v2', async () => {
expect(randomTree.opType === newTree.opType).toBeTruthy()
})

test('decode empty ruledata v2 to NoopRuleData v1', async () => {
const converted = convertRuleDataV2ToV1(decodeRuleDataV2(EncodedNoopRuleData))
expect(converted.operations).toHaveLength(0)
expect(converted.checkOperations).toHaveLength(0)
expect(converted.logicalOperations).toHaveLength(0)
})

// encode/decode should respect address equality semantics but may not maintain case
function addressesEqual(a: string, b: string): boolean {
return a.toLowerCase() === b.toLowerCase()
Expand Down
8 changes: 8 additions & 0 deletions packages/web3/src/entitlement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,14 @@ export function encodeRuleDataV2(ruleData: IRuleEntitlementV2Base.RuleDataV2Stru
}

export function decodeRuleDataV2(entitlementData: Hex): IRuleEntitlementV2Base.RuleDataV2Struct {
if (entitlementData === '0x') {
return {
operations: [],
checkOperations: [],
logicalOperations: [],
} as IRuleEntitlementV2Base.RuleDataV2Struct
}

const getRuleDataV2Abi: ExtractAbiFunction<typeof IRuleEntitlementV2Abi, 'getRuleDataV2'> =
getAbiItem({
abi: IRuleEntitlementV2Abi,
Expand Down

0 comments on commit 1ea5ba0

Please sign in to comment.