Skip to content

Commit

Permalink
fix: use bytes32 for metadataHash
Browse files Browse the repository at this point in the history
Signed-off-by: Tomás Migone <tomas@edgeandnode.com>
  • Loading branch information
tmigone committed Oct 13, 2023
1 parent c807593 commit 473be65
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
16 changes: 8 additions & 8 deletions contracts/build/Registry.abi
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"type": "address[]"
},
{
"internalType": "uint256",
"internalType": "bytes32",
"name": "metadataHash",
"type": "uint256"
"type": "bytes32"
}
],
"indexed": false,
Expand Down Expand Up @@ -73,9 +73,9 @@
"name": "entries",
"outputs": [
{
"internalType": "uint256",
"internalType": "bytes32",
"name": "metadataHash",
"type": "uint256"
"type": "bytes32"
}
],
"stateMutability": "view",
Expand All @@ -97,9 +97,9 @@
"type": "address[]"
},
{
"internalType": "uint256",
"internalType": "bytes32",
"name": "",
"type": "uint256"
"type": "bytes32"
}
],
"stateMutability": "view",
Expand All @@ -120,9 +120,9 @@
"type": "address[]"
},
{
"internalType": "uint256",
"internalType": "bytes32",
"name": "metadataHash",
"type": "uint256"
"type": "bytes32"
}
],
"internalType": "struct Entry",
Expand Down
4 changes: 2 additions & 2 deletions contracts/contracts/Registry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "@openzeppelin/contracts/access/Ownable.sol";
/// @notice Data for an entry, a set of subscriptions contracts and a metadata hash.
struct Entry {
address[] subscriptions;
uint256 metadataHash;
bytes32 metadataHash;
}

/// @notice This contract is designed to store an allowlist of entries, where each entry is associated with a set of
Expand All @@ -33,7 +33,7 @@ contract Registry is Ownable {
}

/// @notice Return the entry data, (subscriptions, metadataHash), associated with the given `_id`.
function getEntry(uint256 _id) external view returns (address[] memory, uint256) {
function getEntry(uint256 _id) external view returns (address[] memory, bytes32) {
Entry memory _entry = entries[_id];
return (_entry.subscriptions, _entry.metadataHash);
}
Expand Down
16 changes: 5 additions & 11 deletions contracts/test/registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as deployment from '../utils/deploy';
import {getAccounts, Account} from '../utils/helpers';

import {Registry} from '../types/contracts/Registry';
import {BigNumber} from 'ethers';
import {BigNumber, ethers} from 'ethers';
import {setAutoMine} from './helpers';

describe('Registry contract', () => {
Expand Down Expand Up @@ -47,9 +47,7 @@ describe('Registry contract', () => {
'0x0000000000000000000000000000000000000001',
'0x0000000000000000000000000000000000000002',
],
metadataHash: BigNumber.from(
'0x0000000000000000000000000000000000000000000000000000000000000001'
),
metadataHash: '0x0000000000000000000000000000000000000000000000000000000000000001',
};
await registry.insertEntry(entryID, entry);
const result = await registry.getEntry(entryID);
Expand All @@ -61,15 +59,11 @@ describe('Registry contract', () => {
const entryID = BigNumber.from(1);
const entry1 = {
subscriptions: ['0x0000000000000000000000000000000000000001'],
metadataHash: BigNumber.from(
'0x0000000000000000000000000000000000000000000000000000000000000001'
),
metadataHash: '0x0000000000000000000000000000000000000000000000000000000000000001',
};
const entry2 = {
subscriptions: ['0x0000000000000000000000000000000000000002'],
metadataHash: BigNumber.from(
'0x0000000000000000000000000000000000000000000000000000000000000002'
),
metadataHash: '0x0000000000000000000000000000000000000000000000000000000000000002',
};
await registry.insertEntry(entryID, entry1);
await registry.insertEntry(entryID, entry2);
Expand All @@ -89,7 +83,7 @@ describe('Registry contract', () => {
await registry.removeEntry(entryID);
const result = await registry.getEntry(entryID);
expect(result[0]).to.eql([]);
expect(result[1]).to.eql(BigNumber.from(0));
expect(result[1]).to.eql(ethers.constants.HashZero);
});
});
});

0 comments on commit 473be65

Please sign in to comment.