test: subgraph matchstick tests for access points and acl refactor (#150)

* fix: errors from deprecated entities.

* fix: events from deprecated entities.

* test: add tests for NewAccessPoint.

* chore: remove yarn-error.log and add it to .gitignore.

* test: add changeAccessPointCreationStatus tests to subgraph matchstick.

* test: add tests for changeAccessPointNameVerify x matchstick

* feat: add utility functions for ACL events

* test: add tests for tokenRoleChanged event

* test: add tests for the CollectionRoleChanged event

* feat: add handleTokenRolesCleared handler function - slipped from the ACL refactor pr.

* refactor: rename the Token owner consts to user consts.

* chore: add .bin to gitignore.
This commit is contained in:
Shredder 2023-03-09 23:22:38 +03:30 committed by GitHub
parent 099e6d76d6
commit e28c7c6e96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 904 additions and 35 deletions

1
subgraph/.gitignore vendored
View File

@ -3,3 +3,4 @@ build
generated
abis
examples/query/.graphclient
tests/matchstick/.bin

1
subgraph/examples/query/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
yarn-error.log

View File

@ -25,6 +25,7 @@ import {
NewAccessPoint as NewAccessPointEvent,
ChangeAccessPointNameVerify as ChangeAccessPointNameVerifyEvent,
ChangeAccessPointContentVerify as ChangeAccessPointContentVerifyEvent,
TokenRolesCleared as TokenRolesClearedEvent
} from '../generated/FleekNFA/FleekNFA';
// Entity Imports [based on the schema]
@ -32,6 +33,7 @@ import {
AccessPoint,
Approval,
ApprovalForAll,
Controller,
Owner,
GitRepository as GitRepositoryEntity,
MetadataUpdate,
@ -285,6 +287,24 @@ export function handleInitialized(event: InitializedEvent): void {
}
}
export function handleTokenRolesCleared(event: TokenRolesClearedEvent): void {
let tokenId = event.params.tokenId;
let byAddress = event.params.byAddress;
// load token
let token = Token.load(Bytes.fromByteArray(Bytes.fromBigInt(tokenId)));
if (!token) {
log.error('Token not found. TokenId: {}', [tokenId.toString()]);
return;
}
// get the list of controllers.
let token_controllers = token.controllers;
token_controllers = [];
token.controllers = token_controllers;
token.save();
}
export function handleCollectionRoleChanged(
event: CollectionRoleChangedEvent
): void {
@ -358,6 +378,7 @@ export function handleTokenRoleChanged(event: TokenRoleChangedEvent): void {
}
}
token.controllers = token_controllers;
token.save();
} else {
log.error('Role not supported. Role: {}, byAddress: {}, toAddress: {}', [
role.toString(),

View File

@ -38,6 +38,7 @@ dataSources:
handler: handleApproval
- event: ApprovalForAll(indexed address,indexed address,bool)
handler: handleApprovalForAll
# Token Events
- event: MetadataUpdate(indexed uint256,string,string,indexed address)
handler: handleMetadataUpdateWithStringValue
- event: MetadataUpdate(indexed uint256,string,string[2],indexed address)
@ -50,6 +51,7 @@ dataSources:
handler: handleNewMint
- event: Transfer(indexed address,indexed address,indexed uint256)
handler: handleTransfer
# Access Control Events
- event: TokenRoleChanged(indexed uint256,indexed uint8,indexed address,bool,address)
handler: handleTokenRoleChanged
- event: TokenRolesCleared(indexed uint256,address)
@ -58,6 +60,7 @@ dataSources:
handler: handleCollectionRoleChanged
- event: Initialized(uint8)
handler: handleInitialized
# Access Point Events
- event: ChangeAccessPointContentVerify(string,uint256,indexed bool,indexed address)
handler: handleChangeAccessPointContentVerify
- event: ChangeAccessPointNameVerify(string,uint256,indexed bool,indexed address)

View File

@ -1,4 +1,4 @@
{
"version": "0.5.4",
"timestamp": 1677510060006
}
"timestamp": 1678390993500
}

View File

@ -0,0 +1,95 @@
import {
assert,
describe,
test,
clearStore,
beforeAll,
afterAll,
} from 'matchstick-as/assembly/index';
import { BigInt, Bytes } from '@graphprotocol/graph-ts';
import { createNewCollectionRoleChanged, handleCollectionRoleChangedList, makeEventId, USER_ONE, USER_TWO } from '../helpers/utils';
import { CollectionRoleChanged } from '../../../generated/FleekNFA/FleekNFA';
describe('Collection Role Changed tests', () => {
beforeAll(() => {
// Collection Role Changed
let collectionRoleChangedList: CollectionRoleChanged[] = [];
collectionRoleChangedList.push(
createNewCollectionRoleChanged(0, 0, USER_ONE, true, USER_TWO) // User Two grants collection owner access to User One
);
collectionRoleChangedList.push(
createNewCollectionRoleChanged(2, 0, USER_ONE, false, USER_TWO) // User Two revokes the owner access of User One to the collection
);
handleCollectionRoleChangedList(collectionRoleChangedList);
});
afterAll(() => {
clearStore();
});
describe('Assertions', () => {
test('Check the `role` field of each CollectionRoleChanged event entity', () => {
assert.fieldEquals(
'CollectionRoleChanged',
makeEventId(0),
'role',
'0'
);
assert.fieldEquals(
'CollectionRoleChanged',
makeEventId(2),
'role',
'0'
);
});
test('Check the `toAddress` field of each CollectionRoleChanged event entity', () => {
assert.fieldEquals(
'CollectionRoleChanged',
makeEventId(0),
'toAddress',
USER_ONE.toString()
);
assert.fieldEquals(
'CollectionRoleChanged',
makeEventId(2),
'toAddress',
USER_ONE.toString()
);
});
test('Check the `byAddress` field of each CollectionRoleChanged event entity', () => {
assert.fieldEquals(
'CollectionRoleChanged',
makeEventId(0),
'byAddress',
USER_TWO.toString()
);
assert.fieldEquals(
'CollectionRoleChanged',
makeEventId(2),
'byAddress',
USER_TWO.toString()
);
});
test('Check the `status` field of each CollectionRoleChanged event entity', () => {
assert.fieldEquals(
'TokenRoleChanged',
makeEventId(0),
'status',
'true'
);
assert.fieldEquals(
'TokenRoleChanged',
makeEventId(2),
'status',
'false'
);
});
});
});

View File

@ -0,0 +1,143 @@
import {
assert,
describe,
test,
clearStore,
beforeAll,
afterAll,
} from 'matchstick-as/assembly/index';
import { BigInt, Bytes } from '@graphprotocol/graph-ts';
import { createNewTokenRoleChanged, handleTokenRoleChangedList, makeEventId, USER_ONE, USER_TWO } from '../helpers/utils';
import { TokenRoleChanged } from '../../../generated/FleekNFA/FleekNFA';
describe('Token Role Changed tests', () => {
beforeAll(() => {
// Token Role Changed
let tokenRoleChangedList: TokenRoleChanged[] = [];
tokenRoleChangedList.push(
createNewTokenRoleChanged(0, BigInt.fromI32(0), 0, USER_ONE, true, USER_TWO) // User Two gives User One controller access to TokenId 0
);
tokenRoleChangedList.push(
createNewTokenRoleChanged(1, BigInt.fromI32(1), 0, USER_TWO, true, USER_ONE) // User One gives User Two controller access to TokenId 1
);
tokenRoleChangedList.push(
createNewTokenRoleChanged(2, BigInt.fromI32(0), 0, USER_ONE, false, USER_TWO) // User Two revokes the controller access of User One to tokenId 0
);
handleTokenRoleChangedList(tokenRoleChangedList);
});
afterAll(() => {
clearStore();
});
describe('Assertions', () => {
test('Check the `tokenId` field of each TokenRoleChanged event entity', () => {
assert.fieldEquals(
'TokenRoleChanged',
makeEventId(0),
'tokenId',
'0'
);
assert.fieldEquals(
'TokenRoleChanged',
makeEventId(1),
'tokenId',
'1'
);
assert.fieldEquals(
'TokenRoleChanged',
makeEventId(2),
'tokenId',
'0'
);
});
test('Check the `role` field of each TokenRoleChanged event entity', () => {
assert.fieldEquals(
'TokenRoleChanged',
makeEventId(0),
'role',
'0'
);
assert.fieldEquals(
'TokenRoleChanged',
makeEventId(1),
'role',
'0'
);
assert.fieldEquals(
'TokenRoleChanged',
makeEventId(2),
'role',
'0'
);
});
test('Check the `toAddress` field of each TokenRoleChanged event entity', () => {
assert.fieldEquals(
'TokenRoleChanged',
makeEventId(0),
'toAddress',
USER_ONE.toString()
);
assert.fieldEquals(
'TokenRoleChanged',
makeEventId(1),
'toAddress',
USER_TWO.toString()
);
assert.fieldEquals(
'TokenRoleChanged',
makeEventId(2),
'toAddress',
USER_ONE.toString()
);
});
test('Check the `byAddress` field of each TokenRoleChanged event entity', () => {
assert.fieldEquals(
'TokenRoleChanged',
makeEventId(0),
'byAddress',
USER_TWO.toString()
);
assert.fieldEquals(
'TokenRoleChanged',
makeEventId(1),
'byAddress',
USER_ONE.toString()
);
assert.fieldEquals(
'TokenRoleChanged',
makeEventId(2),
'byAddress',
USER_TWO.toString()
);
});
test('Check the `status` field of each TokenRoleChanged event entity', () => {
assert.fieldEquals(
'TokenRoleChanged',
makeEventId(0),
'status',
'true'
);
assert.fieldEquals(
'TokenRoleChanged',
makeEventId(1),
'status',
'true'
);
assert.fieldEquals(
'TokenRoleChanged',
makeEventId(2),
'status',
'false'
);
});
});
});

View File

@ -0,0 +1,98 @@
import {
assert,
describe,
test,
clearStore,
beforeAll,
afterAll,
} from 'matchstick-as/assembly/index';
import { BigInt, Bytes } from '@graphprotocol/graph-ts';
import { createNewAccessPointEvent, createNewChangeAccessPointCreationStatus, handleChangeAccessPointCreationStatusList, handleNewAccessPoints, makeEventId, USER_ONE, USER_TWO } from '../helpers/utils';
import { ChangeAccessPointCreationStatus, NewAccessPoint } from '../../../generated/FleekNFA/FleekNFA';
describe('Change Access Point Creation Status tests', () => {
beforeAll(() => {
// New Access Points
let newAccessPoints: NewAccessPoint[] = [];
// User One has two access points: one for tokenId 0 and one for tokenId 1
newAccessPoints.push(
createNewAccessPointEvent(0, 'firstAP', BigInt.fromI32(0), USER_ONE)
);
newAccessPoints.push(
createNewAccessPointEvent(1, 'secondAP', BigInt.fromI32(1), USER_ONE)
);
// User Two has one access point for tokenId 0
newAccessPoints.push(
createNewAccessPointEvent(2, 'thirdAP', BigInt.fromI32(0), USER_TWO)
);
handleNewAccessPoints(newAccessPoints);
});
afterAll(() => {
clearStore();
});
describe('Assertions', () => {
test('Check the `creationStatus` field of each access point entity', () => {
assert.fieldEquals(
'AccessPoint',
'firstAP',
'creationStatus',
'DRAFT'
);
assert.fieldEquals(
'AccessPoint',
'secondAP',
'creationStatus',
'DRAFT'
);
assert.fieldEquals(
'AccessPoint',
'thirdAP',
'creationStatus',
'DRAFT'
);
});
test('Check the `creationStatus` field of each access point entity after changing it', () => {
// New Access Points
let changeAccessPointCreationStatusList: ChangeAccessPointCreationStatus[] = [];
// User One has two access points: one for tokenId 0 and one for tokenId 1
changeAccessPointCreationStatusList.push(
createNewChangeAccessPointCreationStatus(0, 'firstAP', BigInt.fromI32(0), 1, USER_ONE)
);
changeAccessPointCreationStatusList.push(
createNewChangeAccessPointCreationStatus(0, 'secondAP', BigInt.fromI32(1), 1, USER_ONE)
);
// User Two has one access point for tokenId 0
changeAccessPointCreationStatusList.push(
createNewChangeAccessPointCreationStatus(0, 'thirdAP', BigInt.fromI32(0), 1, USER_TWO)
);
handleChangeAccessPointCreationStatusList(changeAccessPointCreationStatusList);
assert.fieldEquals(
'AccessPoint',
'firstAP',
'creationStatus',
'APPROVED'
);
assert.fieldEquals(
'AccessPoint',
'secondAP',
'creationStatus',
'APPROVED'
);
assert.fieldEquals(
'AccessPoint',
'thirdAP',
'creationStatus',
'APPROVED'
);
});
});
});

View File

@ -0,0 +1,96 @@
import {
assert,
describe,
test,
clearStore,
beforeAll,
afterAll,
} from 'matchstick-as/assembly/index';
import { BigInt } from '@graphprotocol/graph-ts';
import { createNewAccessPointEvent, createNewChangeAccessPointNameVerify, handleChangeAccessPointNameVerifies, handleNewAccessPoints, USER_ONE, USER_TWO } from '../helpers/utils';
import { ChangeAccessPointNameVerify, NewAccessPoint } from '../../../generated/FleekNFA/FleekNFA';
describe('Change Access Point Name Verify tests', () => {
beforeAll(() => {
// New Access Points
let newAccessPoints: NewAccessPoint[] = [];
// User One has two access points: one for tokenId 0 and one for tokenId 1
newAccessPoints.push(
createNewAccessPointEvent(0, 'firstAP', BigInt.fromI32(0), USER_ONE)
);
newAccessPoints.push(
createNewAccessPointEvent(1, 'secondAP', BigInt.fromI32(1), USER_ONE)
);
// User Two has one access point for tokenId 0
newAccessPoints.push(
createNewAccessPointEvent(2, 'thirdAP', BigInt.fromI32(0), USER_TWO)
);
handleNewAccessPoints(newAccessPoints);
});
afterAll(() => {
clearStore();
});
describe('Assertions', () => {
test('Check the `nameVerified` field of each access point entity', () => {
assert.fieldEquals(
'AccessPoint',
'firstAP',
'nameVerified',
'false'
);
assert.fieldEquals(
'AccessPoint',
'secondAP',
'nameVerified',
'false'
);
assert.fieldEquals(
'AccessPoint',
'thirdAP',
'nameVerified',
'false'
);
});
test('Check the `nameVerified` field of each access point entity after changing it', () => {
// New Access Point Name Verified fields
let changeAccessPointNameVerifies: ChangeAccessPointNameVerify[] = [];
changeAccessPointNameVerifies.push(
createNewChangeAccessPointNameVerify(0, 'firstAP', BigInt.fromI32(0), true, USER_ONE)
);
changeAccessPointNameVerifies.push(
createNewChangeAccessPointNameVerify(0, 'secondAP', BigInt.fromI32(1), true, USER_ONE)
);
changeAccessPointNameVerifies.push(
createNewChangeAccessPointNameVerify(0, 'thirdAP', BigInt.fromI32(0), true, USER_TWO)
);
handleChangeAccessPointNameVerifies(changeAccessPointNameVerifies);
assert.fieldEquals(
'AccessPoint',
'firstAP',
'nameVerified',
'true'
);
assert.fieldEquals(
'AccessPoint',
'secondAP',
'nameVerified',
'true'
);
assert.fieldEquals(
'AccessPoint',
'thirdAP',
'nameVerified',
'true'
);
});
});
});

View File

@ -0,0 +1,109 @@
import {
assert,
describe,
test,
clearStore,
beforeAll,
afterAll,
} from 'matchstick-as/assembly/index';
import { BigInt, Bytes } from '@graphprotocol/graph-ts';
import { createNewAccessPointEvent, handleNewAccessPoints, makeEventId, USER_ONE, USER_TWO } from '../helpers/utils';
import { NewAccessPoint } from '../../../generated/FleekNFA/FleekNFA';
describe('New Access Point tests', () => {
beforeAll(() => {
// New Access Points
let newAccessPoints: NewAccessPoint[] = [];
// User One has two access points: one for tokenId 0 and one for tokenId 1
newAccessPoints.push(
createNewAccessPointEvent(0, 'firstAP', BigInt.fromI32(0), USER_ONE)
);
newAccessPoints.push(
createNewAccessPointEvent(1, 'secondAP', BigInt.fromI32(1), USER_ONE)
);
// User Two has one access point for tokenId 0
newAccessPoints.push(
createNewAccessPointEvent(2, 'thirdAP', BigInt.fromI32(0), USER_TWO)
);
handleNewAccessPoints(newAccessPoints);
});
afterAll(() => {
clearStore();
});
describe('Assertions', () => {
test('Check the number of `NewAccessPoint` events to be valid', () => {
assert.entityCount('NewAccessPoint', 3);
});
test('Check the `apName` field of each event', () => {
assert.fieldEquals(
'NewAccessPoint',
makeEventId(0),
'apName',
'firstAP'.toString()
);
assert.fieldEquals(
'NewAccessPoint',
makeEventId(1),
'apName',
'secondAP'.toString()
);
assert.fieldEquals(
'NewAccessPoint',
makeEventId(2),
'apName',
'thirdAP'.toString()
);
});
test('Check the `tokenId` field of each event', () => {
assert.fieldEquals(
'NewAccessPoint',
makeEventId(0),
'tokenId',
'0'
);
assert.fieldEquals(
'NewAccessPoint',
makeEventId(1),
'tokenId',
'1'
);
assert.fieldEquals(
'NewAccessPoint',
makeEventId(2),
'tokenId',
'0'
);
});
test('Check the `owner` field of each event', () => {
assert.fieldEquals(
'NewAccessPoint',
makeEventId(0),
'owner',
USER_ONE.toString()
);
assert.fieldEquals(
'NewAccessPoint',
makeEventId(1),
'owner',
USER_ONE.toString()
);
assert.fieldEquals(
'NewAccessPoint',
makeEventId(2),
'owner',
USER_TWO.toString()
);
});
test('check the existence of a nonexistent event in the database', () => {
assert.notInStore('NewAccessPoint', makeEventId(3));
});
});
});

View File

@ -5,12 +5,24 @@ import {
ApprovalForAll as ApprovalForAllEvent,
Transfer as TransferEvent,
NewMint as NewMintEvent,
NewAccessPoint,
ChangeAccessPointCreationStatus,
ChangeAccessPointNameVerify,
TokenRoleChanged,
CollectionRoleChanged,
TokenRolesCleared
} from '../../../generated/FleekNFA/FleekNFA';
import {
handleApproval,
handleApprovalForAll,
handleChangeAccessPointCreationStatus,
handleChangeAccessPointNameVerify,
handleNewAccessPoint,
handleNewMint,
handleTransfer,
handleTokenRoleChanged,
handleCollectionRoleChanged,
handleTokenRolesCleared,
} from '../../../src/fleek-nfa';
export function createApprovalEvent(
@ -161,16 +173,270 @@ export function createNewMintEvent(
return newMintEvent;
}
export function createNewAccessPointEvent(
event_count: i32,
apName: string,
tokenId: BigInt,
owner: Address
): NewAccessPoint {
let newAccessPoint = changetype<NewAccessPoint>(newMockEvent());
newAccessPoint.parameters = new Array();
newAccessPoint.parameters.push(
new ethereum.EventParam(
'apName',
ethereum.Value.fromString(apName.toString())
)
);
newAccessPoint.parameters.push(
new ethereum.EventParam(
'tokenId',
ethereum.Value.fromUnsignedBigInt(tokenId)
)
);
newAccessPoint.parameters.push(
new ethereum.EventParam(
'owner',
ethereum.Value.fromAddress(owner)
)
);
newAccessPoint.transaction.hash = Bytes.fromI32(event_count);
newAccessPoint.logIndex = new BigInt(event_count);
return newAccessPoint;
}
export function createNewChangeAccessPointCreationStatus(
event_count: i32,
apName: string,
tokenId: BigInt,
status: i32,
triggeredBy: Address
): ChangeAccessPointCreationStatus {
let changeAccessPointCreationStatus = changetype<ChangeAccessPointCreationStatus>(newMockEvent());
changeAccessPointCreationStatus.parameters = new Array();
changeAccessPointCreationStatus.parameters.push(
new ethereum.EventParam(
'apName',
ethereum.Value.fromString(apName.toString())
)
);
changeAccessPointCreationStatus.parameters.push(
new ethereum.EventParam(
'tokenId',
ethereum.Value.fromUnsignedBigInt(tokenId)
)
);
changeAccessPointCreationStatus.parameters.push(
new ethereum.EventParam(
'creationStatus',
ethereum.Value.fromI32(status)
)
);
changeAccessPointCreationStatus.parameters.push(
new ethereum.EventParam(
'triggeredBy',
ethereum.Value.fromAddress(triggeredBy)
)
);
changeAccessPointCreationStatus.transaction.hash = Bytes.fromI32(event_count);
changeAccessPointCreationStatus.logIndex = new BigInt(event_count);
return changeAccessPointCreationStatus;
}
export function createNewChangeAccessPointNameVerify(
event_count: i32,
apName: string,
tokenId: BigInt,
verified: boolean,
triggeredBy: Address
): ChangeAccessPointNameVerify {
let changeAccessPointNameVerify = changetype<ChangeAccessPointNameVerify>(newMockEvent());
changeAccessPointNameVerify.parameters = new Array();
changeAccessPointNameVerify.parameters.push(
new ethereum.EventParam(
'apName',
ethereum.Value.fromString(apName.toString())
)
);
changeAccessPointNameVerify.parameters.push(
new ethereum.EventParam(
'tokenId',
ethereum.Value.fromUnsignedBigInt(tokenId)
)
);
changeAccessPointNameVerify.parameters.push(
new ethereum.EventParam(
'verified',
ethereum.Value.fromBoolean(verified)
)
);
changeAccessPointNameVerify.parameters.push(
new ethereum.EventParam(
'triggeredBy',
ethereum.Value.fromAddress(triggeredBy)
)
);
changeAccessPointNameVerify.transaction.hash = Bytes.fromI32(event_count);
changeAccessPointNameVerify.logIndex = new BigInt(event_count);
return changeAccessPointNameVerify;
}
export function createNewTokenRoleChanged(
event_count: i32,
tokenId: BigInt,
role: i32,
toAddress: Address,
status: boolean,
byAddress: Address
): TokenRoleChanged {
let tokenRoleChanged = changetype<TokenRoleChanged>(newMockEvent());
tokenRoleChanged.parameters = new Array();
tokenRoleChanged.parameters.push(
new ethereum.EventParam(
'tokenId',
ethereum.Value.fromUnsignedBigInt(tokenId)
)
);
tokenRoleChanged.parameters.push(
new ethereum.EventParam(
'role',
ethereum.Value.fromI32(role)
)
);
tokenRoleChanged.parameters.push(
new ethereum.EventParam(
'toAddress',
ethereum.Value.fromAddress(toAddress)
)
);
tokenRoleChanged.parameters.push(
new ethereum.EventParam(
'status',
ethereum.Value.fromBoolean(status)
)
);
tokenRoleChanged.parameters.push(
new ethereum.EventParam(
'byAddress',
ethereum.Value.fromAddress(byAddress)
)
);
tokenRoleChanged.transaction.hash = Bytes.fromI32(event_count);
tokenRoleChanged.logIndex = new BigInt(event_count);
return tokenRoleChanged;
}
export function createNewCollectionRoleChanged(
event_count: i32,
role: i32,
toAddress: Address,
status: boolean,
byAddress: Address
): CollectionRoleChanged {
let collectionRoleChanged = changetype<CollectionRoleChanged>(newMockEvent());
collectionRoleChanged.parameters = new Array();
collectionRoleChanged.parameters.push(
new ethereum.EventParam(
'role',
ethereum.Value.fromI32(role)
)
);
collectionRoleChanged.parameters.push(
new ethereum.EventParam(
'toAddress',
ethereum.Value.fromAddress(toAddress)
)
);
collectionRoleChanged.parameters.push(
new ethereum.EventParam(
'status',
ethereum.Value.fromBoolean(status)
)
);
collectionRoleChanged.parameters.push(
new ethereum.EventParam(
'byAddress',
ethereum.Value.fromAddress(byAddress)
)
);
collectionRoleChanged.transaction.hash = Bytes.fromI32(event_count);
collectionRoleChanged.logIndex = new BigInt(event_count);
return collectionRoleChanged;
}
export function createNewTokenRolesCleared(
event_count: i32,
tokenId: BigInt,
byAddress: Address
): TokenRolesCleared {
let tokenRolesCleared = changetype<TokenRolesCleared>(newMockEvent());
tokenRolesCleared.parameters = new Array();
tokenRolesCleared.parameters.push(
new ethereum.EventParam(
'tokenId',
ethereum.Value.fromUnsignedBigInt(tokenId)
)
);
tokenRolesCleared.parameters.push(
new ethereum.EventParam(
'byAddress',
ethereum.Value.fromAddress(byAddress)
)
);
tokenRolesCleared.transaction.hash = Bytes.fromI32(event_count);
tokenRolesCleared.logIndex = new BigInt(event_count);
return tokenRolesCleared;
}
export const CONTRACT: Address = Address.fromString(
'0x0000000000000000000000000000000000000000'
);
export const CONTRACT_OWNER: Address = Address.fromString(
'0x1000000000000000000000000000000000000001'
);
export const TOKEN_OWNER_ONE: Address = Address.fromString(
export const USER_ONE: Address = Address.fromString(
'0x2000000000000000000000000000000000000002'
);
export const TOKEN_OWNER_TWO: Address = Address.fromString(
export const USER_TWO: Address = Address.fromString(
'0x3000000000000000000000000000000000000003'
);
@ -198,6 +464,42 @@ export function handleApprovalForAlls(events: ApprovalForAllEvent[]): void {
});
}
export function handleNewAccessPoints(events: NewAccessPoint[]): void {
events.forEach((event) => {
handleNewAccessPoint(event);
});
}
export function handleChangeAccessPointCreationStatusList(events: ChangeAccessPointCreationStatus[]): void {
events.forEach((event) => {
handleChangeAccessPointCreationStatus(event);
});
}
export function handleChangeAccessPointNameVerifies(events: ChangeAccessPointNameVerify[]): void {
events.forEach((event) => {
handleChangeAccessPointNameVerify(event);
});
}
export function handleTokenRoleChangedList(events: TokenRoleChanged[]): void {
events.forEach((event) => {
handleTokenRoleChanged(event);
});
}
export function handleCollectionRoleChangedList(events: CollectionRoleChanged[]): void {
events.forEach((event) => {
handleCollectionRoleChanged(event);
});
}
export function handleTokenRolesClearedList(events: TokenRolesCleared[]): void {
events.forEach((event) => {
handleTokenRolesCleared(event);
});
}
export function makeEventId(id: i32): string {
return Bytes.fromI32(id).toHexString() + '00000000';
}

View File

@ -16,8 +16,8 @@ import {
handleNewMints,
handleTransfers,
makeEventId,
TOKEN_OWNER_ONE,
TOKEN_OWNER_TWO,
USER_ONE,
USER_TWO,
} from './helpers/utils';
import { NewMint, Transfer } from '../../generated/FleekNFA/FleekNFA';
@ -25,42 +25,42 @@ describe('Owner tests', () => {
beforeAll(() => {
// NEW MINTS
let newMints: NewMint[] = [];
newMints.push(createNewMintEvent(0, TOKEN_OWNER_ONE, BigInt.fromI32(0)));
newMints.push(createNewMintEvent(1, TOKEN_OWNER_TWO, BigInt.fromI32(1)));
newMints.push(createNewMintEvent(2, TOKEN_OWNER_ONE, BigInt.fromI32(2)));
newMints.push(createNewMintEvent(3, TOKEN_OWNER_ONE, BigInt.fromI32(3)));
newMints.push(createNewMintEvent(4, TOKEN_OWNER_TWO, BigInt.fromI32(4)));
newMints.push(createNewMintEvent(0, USER_ONE, BigInt.fromI32(0)));
newMints.push(createNewMintEvent(1, USER_TWO, BigInt.fromI32(1)));
newMints.push(createNewMintEvent(2, USER_ONE, BigInt.fromI32(2)));
newMints.push(createNewMintEvent(3, USER_ONE, BigInt.fromI32(3)));
newMints.push(createNewMintEvent(4, USER_TWO, BigInt.fromI32(4)));
handleNewMints(newMints);
// TRANSFERS
let transfers: Transfer[] = [];
transfers.push(
createTransferEvent(0, CONTRACT, TOKEN_OWNER_ONE, BigInt.fromI32(0))
createTransferEvent(0, CONTRACT, USER_ONE, BigInt.fromI32(0))
);
transfers.push(
createTransferEvent(1, CONTRACT, TOKEN_OWNER_TWO, BigInt.fromI32(1))
createTransferEvent(1, CONTRACT, USER_TWO, BigInt.fromI32(1))
);
transfers.push(
createTransferEvent(2, CONTRACT, TOKEN_OWNER_ONE, BigInt.fromI32(2))
createTransferEvent(2, CONTRACT, USER_ONE, BigInt.fromI32(2))
);
transfers.push(
createTransferEvent(3, CONTRACT, TOKEN_OWNER_ONE, BigInt.fromI32(3))
createTransferEvent(3, CONTRACT, USER_ONE, BigInt.fromI32(3))
);
transfers.push(
createTransferEvent(
4,
TOKEN_OWNER_TWO,
TOKEN_OWNER_ONE,
USER_TWO,
USER_ONE,
BigInt.fromI32(1)
)
);
transfers.push(
createTransferEvent(5, CONTRACT, TOKEN_OWNER_TWO, BigInt.fromI32(4))
createTransferEvent(5, CONTRACT, USER_TWO, BigInt.fromI32(4))
);
transfers.push(
createTransferEvent(
6,
TOKEN_OWNER_ONE,
TOKEN_OWNER_TWO,
USER_ONE,
USER_TWO,
BigInt.fromI32(0)
)
);
@ -129,15 +129,15 @@ describe('Owner tests', () => {
test('Check the existence of owners in store', () => {
assert.fieldEquals(
'Owner',
TOKEN_OWNER_ONE.toHexString(),
USER_ONE.toHexString(),
'id',
TOKEN_OWNER_ONE.toHexString()
USER_ONE.toHexString()
);
assert.fieldEquals(
'Owner',
TOKEN_OWNER_TWO.toHexString(),
USER_TWO.toHexString(),
'id',
TOKEN_OWNER_TWO.toHexString()
USER_TWO.toHexString()
);
});
});

View File

@ -14,8 +14,8 @@ import {
createTransferEvent,
handleTransfers,
makeEventId,
TOKEN_OWNER_ONE,
TOKEN_OWNER_TWO,
USER_ONE,
USER_TWO,
} from './helpers/utils';
import { Transfer } from '../../generated/FleekNFA/FleekNFA';
@ -24,33 +24,33 @@ describe('Transfer tests', () => {
// TRANSFERS
let transfers: Transfer[] = [];
transfers.push(
createTransferEvent(0, CONTRACT, TOKEN_OWNER_ONE, BigInt.fromI32(0))
createTransferEvent(0, CONTRACT, USER_ONE, BigInt.fromI32(0))
);
transfers.push(
createTransferEvent(1, CONTRACT, TOKEN_OWNER_TWO, BigInt.fromI32(1))
createTransferEvent(1, CONTRACT, USER_TWO, BigInt.fromI32(1))
);
transfers.push(
createTransferEvent(2, CONTRACT, TOKEN_OWNER_ONE, BigInt.fromI32(2))
createTransferEvent(2, CONTRACT, USER_ONE, BigInt.fromI32(2))
);
transfers.push(
createTransferEvent(3, CONTRACT, TOKEN_OWNER_ONE, BigInt.fromI32(3))
createTransferEvent(3, CONTRACT, USER_ONE, BigInt.fromI32(3))
);
transfers.push(
createTransferEvent(
4,
TOKEN_OWNER_TWO,
TOKEN_OWNER_ONE,
USER_TWO,
USER_ONE,
BigInt.fromI32(1)
)
);
transfers.push(
createTransferEvent(5, CONTRACT, TOKEN_OWNER_TWO, BigInt.fromI32(4))
createTransferEvent(5, CONTRACT, USER_TWO, BigInt.fromI32(4))
);
transfers.push(
createTransferEvent(
6,
TOKEN_OWNER_ONE,
TOKEN_OWNER_TWO,
USER_ONE,
USER_TWO,
BigInt.fromI32(0)
)
);