feat(Identity): implement IdentityUpdate event [32]

This commit is contained in:
Bob Stockdale
2023-10-10 17:10:57 -04:00
parent 5d2d839313
commit 4e11470435
3 changed files with 54 additions and 1 deletions

View File

@@ -79,6 +79,37 @@
"name": "BatchMetadataUpdate",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "wallet",
"type": "address"
},
{
"indexed": false,
"internalType": "string",
"name": "platformId",
"type": "string"
},
{
"indexed": false,
"internalType": "string",
"name": "platformUserId",
"type": "string"
},
{
"indexed": false,
"internalType": "string",
"name": "platformUsername",
"type": "string"
}
],
"name": "IdentityUpdate",
"type": "event"
},
{
"anonymous": false,
"inputs": [

View File

@@ -18,6 +18,13 @@ contract Identity is IIdentity, ERC721URIStorage {
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
event IdentityUpdate(
address wallet,
string platformId,
string platformUserId,
string platformUsername
);
string constant MSGPREFIX = "\x19Ethereum Signed Message:\n";
bytes4 internal constant MAGICVALUE = 0x1626ba7e;
@@ -80,7 +87,12 @@ contract Identity is IIdentity, ERC721URIStorage {
walletForPlatformUser[_platformId][_platformUserId] = _userAddress;
// TODO: emit wallet association event
emit IdentityUpdate(
_userAddress,
_platformId,
_platformUserId,
_platformUsername
);
}
function getTokenURI(string memory platformId, uint256 tokenId)

View File

@@ -31,6 +31,16 @@ describe("Identity", () => {
expect(txn.hash).to.be.a.string;
});
it("should emit an IdentityUpdate event", async () => {
// given
const { identity, signer, user } = await identityFixture();
const params = [user.address, "1", "123", "coder1"];
const signature = await mintSignature(params, signer);
// when/then
expect(await identity.mint(params[0], params[1], params[2], params[3], signature)).to.emit(identity, "IdentityUpdate").withArgs(params);
});
it("fails to mint identity NFT with invalid signature", async () => {
const { identity, user } = await identityFixture();
const params = [user.address, "1", "123", "coder1"];