test: base layout of the subgraph tests and fixing deprecated events (#145)
* test: restructure the dir, add config file, divide transfer tests to a separate file. * test: divide newTokenName tests. * test: add tests for NewTokenENS, build, external urls, description. * fix: update tests in newTokenENS. * test: add owner tests. * feat: add compile command to subgraph package.json * test: remove deprecated events and their handlers and tests. add newmint mock handler. * fix: error in the order of passed parameters in NewMint mock creator function.
This commit is contained in:
parent
b8b8cb28ea
commit
751983ff37
|
|
@ -0,0 +1,2 @@
|
|||
testsFolder: tests/matchstick/
|
||||
manifestPath: subgraph.yaml
|
||||
|
|
@ -7,7 +7,8 @@
|
|||
"create-local": "graph create --node http://localhost:8020/ FleekNFA",
|
||||
"remove-local": "graph remove --node http://localhost:8020/ FleekNFA",
|
||||
"deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 FleekNFA",
|
||||
"test": "graph test"
|
||||
"test": "graph test",
|
||||
"compile": "cd ../contracts && yarn && yarn compile && cd ../subgraph && yarn codegen"
|
||||
},
|
||||
"dependencies": {
|
||||
"@graphprotocol/graph-cli": "0.37.2",
|
||||
|
|
|
|||
|
|
@ -18,26 +18,6 @@ type ApprovalForAll @entity(immutable: true) {
|
|||
transactionHash: Bytes!
|
||||
}
|
||||
|
||||
type CollectionRoleGranted @entity(immutable: true) {
|
||||
id: Bytes!
|
||||
role: Int! # uint8
|
||||
toAddress: Bytes! # address
|
||||
byAddress: Bytes! # address
|
||||
blockNumber: BigInt!
|
||||
blockTimestamp: BigInt!
|
||||
transactionHash: Bytes!
|
||||
}
|
||||
|
||||
type CollectionRoleRevoked @entity(immutable: true) {
|
||||
id: Bytes!
|
||||
role: Int! # uint8
|
||||
toAddress: Bytes! # address
|
||||
byAddress: Bytes! # address
|
||||
blockNumber: BigInt!
|
||||
blockTimestamp: BigInt!
|
||||
transactionHash: Bytes!
|
||||
}
|
||||
|
||||
type NewMint @entity(immutable: true) {
|
||||
id: Bytes!
|
||||
tokenId: BigInt! # uint256
|
||||
|
|
@ -70,28 +50,6 @@ type MetadataUpdate @entity(immutable: true) {
|
|||
transactionHash: Bytes!
|
||||
}
|
||||
|
||||
type TokenRoleGranted @entity(immutable: true) {
|
||||
id: Bytes!
|
||||
tokenId: BigInt! # uint256
|
||||
role: Int! # uint8
|
||||
toAddress: Bytes! # address
|
||||
byAddress: Bytes! # address
|
||||
blockNumber: BigInt!
|
||||
blockTimestamp: BigInt!
|
||||
transactionHash: Bytes!
|
||||
}
|
||||
|
||||
type TokenRoleRevoked @entity(immutable: true) {
|
||||
id: Bytes!
|
||||
tokenId: BigInt! # uint256
|
||||
role: Int! # uint8
|
||||
toAddress: Bytes! # address
|
||||
byAddress: Bytes! # address
|
||||
blockNumber: BigInt!
|
||||
blockTimestamp: BigInt!
|
||||
transactionHash: Bytes!
|
||||
}
|
||||
|
||||
type Transfer @entity(immutable: true) {
|
||||
id: Bytes!
|
||||
from: Bytes! # address
|
||||
|
|
|
|||
|
|
@ -2,13 +2,9 @@ import { Address, Bytes, log, store, ethereum } from '@graphprotocol/graph-ts';
|
|||
import {
|
||||
Approval as ApprovalEvent,
|
||||
ApprovalForAll as ApprovalForAllEvent,
|
||||
CollectionRoleGranted as CollectionRoleGrantedEvent,
|
||||
CollectionRoleRevoked as CollectionRoleRevokedEvent,
|
||||
MetadataUpdate as MetadataUpdateEvent,
|
||||
MetadataUpdate1 as MetadataUpdateEvent1,
|
||||
MetadataUpdate2 as MetadataUpdateEvent2,
|
||||
TokenRoleGranted as TokenRoleGrantedEvent,
|
||||
TokenRoleRevoked as TokenRoleRevokedEvent,
|
||||
Transfer as TransferEvent,
|
||||
NewMint as NewMintEvent,
|
||||
} from '../generated/FleekNFA/FleekNFA';
|
||||
|
|
@ -17,16 +13,12 @@ import {
|
|||
ApprovalForAll,
|
||||
Collection,
|
||||
CollectionOwner,
|
||||
CollectionRoleGranted,
|
||||
CollectionRoleRevoked,
|
||||
Controller,
|
||||
GitRepository as GitRepositoryEntity,
|
||||
MetadataUpdate,
|
||||
NewMint,
|
||||
Owner,
|
||||
Token,
|
||||
TokenRoleGranted,
|
||||
TokenRoleRevoked,
|
||||
Transfer,
|
||||
} from '../generated/schema';
|
||||
|
||||
|
|
@ -60,92 +52,6 @@ export function handleApprovalForAll(event: ApprovalForAllEvent): void {
|
|||
entity.save();
|
||||
}
|
||||
|
||||
export function handleCollectionRoleGranted(
|
||||
event: CollectionRoleGrantedEvent
|
||||
): void {
|
||||
let entity = new CollectionRoleGranted(
|
||||
event.transaction.hash.concatI32(event.logIndex.toI32())
|
||||
);
|
||||
entity.role = event.params.role;
|
||||
entity.toAddress = event.params.toAddress;
|
||||
entity.byAddress = event.params.byAddress;
|
||||
|
||||
entity.blockNumber = event.block.number;
|
||||
entity.blockTimestamp = event.block.timestamp;
|
||||
entity.transactionHash = event.transaction.hash;
|
||||
|
||||
entity.save();
|
||||
|
||||
if (event.params.role === 0) {
|
||||
// Role 0 => Owner [Probably going to change this after the ACL refactor.]
|
||||
// Should create a new CollectionOwner entity with the address from the parameters.
|
||||
// If it already is a collection owner, should log a warning.
|
||||
|
||||
let collectionOwner = CollectionOwner.load(event.params.toAddress);
|
||||
|
||||
if (collectionOwner) {
|
||||
// Collection Owner already exists.
|
||||
// Print warning log message.
|
||||
log.warning(
|
||||
'Although Address {} is already a collection owner, a CollectionRoleGranted event was emitted that indicated the address was granted the same role, again.',
|
||||
[event.params.toAddress.toHexString()]
|
||||
);
|
||||
} else {
|
||||
// Create a new collection owner entity and assign the values
|
||||
collectionOwner = new CollectionOwner(event.params.toAddress);
|
||||
collectionOwner.accessGrantedBy = event.params.byAddress;
|
||||
collectionOwner.transactionHash = event.transaction.hash;
|
||||
|
||||
// Log the new CollectionOwner entity creation.
|
||||
log.info('Created a new collection owner entity with address {}.', [
|
||||
event.params.toAddress.toHexString(),
|
||||
]);
|
||||
|
||||
// Save the collection owner.
|
||||
collectionOwner.save();
|
||||
}
|
||||
|
||||
if (event.params.byAddress === event.params.toAddress) {
|
||||
// This is the contract creation transaction.
|
||||
log.warning('This is the contract creation transaction.', []);
|
||||
if (event.receipt) {
|
||||
let receipt = event.receipt as ethereum.TransactionReceipt;
|
||||
log.warning('Contract address is: {}', [
|
||||
receipt.contractAddress.toHexString(),
|
||||
]);
|
||||
let collection = new Collection(receipt.contractAddress);
|
||||
collection.deployer = event.params.byAddress;
|
||||
collection.transactionHash = event.transaction.hash;
|
||||
collection.owners = [event.params.toAddress];
|
||||
collection.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function handleCollectionRoleRevoked(
|
||||
event: CollectionRoleRevokedEvent
|
||||
): void {
|
||||
let entity = new CollectionRoleRevoked(
|
||||
event.transaction.hash.concatI32(event.logIndex.toI32())
|
||||
);
|
||||
entity.role = event.params.role;
|
||||
entity.toAddress = event.params.toAddress;
|
||||
entity.byAddress = event.params.byAddress;
|
||||
|
||||
entity.blockNumber = event.block.number;
|
||||
entity.blockTimestamp = event.block.timestamp;
|
||||
entity.transactionHash = event.transaction.hash;
|
||||
|
||||
entity.save();
|
||||
|
||||
if (event.params.role === 0) {
|
||||
// Role 0 => Owner [Probably going to change this after the ACL refactor.]
|
||||
// Should remove the CollectionOwner entity.
|
||||
|
||||
store.remove('CollectionOwner', event.params.toAddress.toHexString());
|
||||
}
|
||||
}
|
||||
export function handleNewMint(event: NewMintEvent): void {
|
||||
let newMintEntity = new NewMint(
|
||||
event.transaction.hash.concatI32(event.logIndex.toI32())
|
||||
|
|
@ -179,6 +85,7 @@ export function handleNewMint(event: NewMintEvent): void {
|
|||
newMintEntity.blockTimestamp = event.block.timestamp;
|
||||
newMintEntity.transactionHash = event.transaction.hash;
|
||||
newMintEntity.save();
|
||||
log.error('{}', [tokenId.toString()]);
|
||||
|
||||
// Create Token, Owner, and Controller entities
|
||||
|
||||
|
|
@ -343,109 +250,6 @@ export function handleMetadataUpdateWithIntValue(
|
|||
}
|
||||
}
|
||||
|
||||
export function handleTokenRoleGranted(event: TokenRoleGrantedEvent): void {
|
||||
let entity = new TokenRoleGranted(
|
||||
event.transaction.hash.concatI32(event.logIndex.toI32())
|
||||
);
|
||||
entity.tokenId = event.params.tokenId;
|
||||
entity.role = event.params.role;
|
||||
entity.toAddress = event.params.toAddress;
|
||||
entity.byAddress = event.params.byAddress;
|
||||
|
||||
entity.blockNumber = event.block.number;
|
||||
entity.blockTimestamp = event.block.timestamp;
|
||||
entity.transactionHash = event.transaction.hash;
|
||||
|
||||
entity.save();
|
||||
|
||||
if (event.params.role === 1) {
|
||||
// This is a new controller being added to a token.
|
||||
// First we add the controller to the token's list of controllers.
|
||||
// Then we create a new controller entity.
|
||||
|
||||
let token = Token.load(
|
||||
Bytes.fromByteArray(Bytes.fromBigInt(event.params.tokenId))
|
||||
);
|
||||
let controller = Controller.load(event.params.toAddress);
|
||||
|
||||
if (!controller) {
|
||||
// Create a new controller entity
|
||||
controller = new Controller(event.params.toAddress);
|
||||
}
|
||||
|
||||
if (token !== null) {
|
||||
let token_controllers = token.controllers;
|
||||
if (!token_controllers) {
|
||||
token_controllers = [];
|
||||
}
|
||||
token_controllers.push(event.params.toAddress);
|
||||
token.controllers = token_controllers;
|
||||
} else {
|
||||
log.error(
|
||||
'Handling controller access granted event for tokenId {}. THE TOKEN DOES NOT EXIST. FAILED TO UPDATE THE TOKEN ENTITY.',
|
||||
[event.params.tokenId.toHexString()]
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
controller.save();
|
||||
token.save();
|
||||
}
|
||||
}
|
||||
|
||||
export function handleTokenRoleRevoked(event: TokenRoleRevokedEvent): void {
|
||||
let entity = new TokenRoleRevoked(
|
||||
event.transaction.hash.concatI32(event.logIndex.toI32())
|
||||
);
|
||||
entity.tokenId = event.params.tokenId;
|
||||
entity.role = event.params.role;
|
||||
entity.toAddress = event.params.toAddress;
|
||||
entity.byAddress = event.params.byAddress;
|
||||
|
||||
entity.blockNumber = event.block.number;
|
||||
entity.blockTimestamp = event.block.timestamp;
|
||||
entity.transactionHash = event.transaction.hash;
|
||||
|
||||
entity.save();
|
||||
|
||||
if (event.params.role === 1) {
|
||||
// This is a controller being removed from a token.
|
||||
|
||||
// Load the token with the tokenId.
|
||||
let token = Token.load(
|
||||
Bytes.fromByteArray(Bytes.fromBigInt(event.params.tokenId))
|
||||
);
|
||||
|
||||
// Check if the token entity exists.
|
||||
if (token !== null) {
|
||||
// get the list of controllers.
|
||||
let token_controllers = token.controllers;
|
||||
if (!token_controllers) {
|
||||
token_controllers = [];
|
||||
}
|
||||
|
||||
// remove address from the controllers list
|
||||
const index = token_controllers.indexOf(event.params.toAddress, 0);
|
||||
if (index > -1) {
|
||||
token_controllers.splice(index, 1);
|
||||
}
|
||||
|
||||
// assign the new controllers list
|
||||
token.controllers = token_controllers;
|
||||
} else {
|
||||
// the token does not exist
|
||||
log.error(
|
||||
'Handling controller access revoked event for tokenId {}. THE TOKEN DOES NOT EXIST. FAILED TO UPDATE THE TOKEN ENTITY.',
|
||||
[event.params.tokenId.toHexString()]
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// save the token data
|
||||
token.save();
|
||||
}
|
||||
}
|
||||
|
||||
export function handleTransfer(event: TransferEvent): void {
|
||||
let entity = new Transfer(
|
||||
event.transaction.hash.concatI32(event.logIndex.toI32())
|
||||
|
|
|
|||
|
|
@ -42,16 +42,8 @@ dataSources:
|
|||
handler: handleMetadataUpdateWithDoubleStringValue
|
||||
- event: MetadataUpdate(indexed uint256,string,uint24,indexed address)
|
||||
handler: handleMetadataUpdateWithIntValue
|
||||
- event: CollectionRoleGranted(indexed uint8,indexed address,address)
|
||||
handler: handleCollectionRoleGranted
|
||||
- event: CollectionRoleRevoked(indexed uint8,indexed address,address)
|
||||
handler: handleCollectionRoleRevoked
|
||||
- event: NewMint(indexed uint256,string,string,string,string,string,string,string,uint24,bool,indexed address,indexed address)
|
||||
handler: handleNewMint
|
||||
- event: TokenRoleGranted(indexed uint256,indexed uint8,indexed address,address)
|
||||
handler: handleTokenRoleGranted
|
||||
- event: TokenRoleRevoked(indexed uint256,indexed uint8,indexed address,address)
|
||||
handler: handleTokenRoleRevoked
|
||||
- event: Transfer(indexed address,indexed address,indexed uint256)
|
||||
handler: handleTransfer
|
||||
file: ./src/fleek-nfa.ts
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
{
|
||||
"version": "0.5.4",
|
||||
"timestamp": 1675972891956
|
||||
}
|
||||
|
|
@ -1,498 +0,0 @@
|
|||
import {
|
||||
assert,
|
||||
describe,
|
||||
test,
|
||||
clearStore,
|
||||
beforeAll,
|
||||
afterAll,
|
||||
logStore,
|
||||
log,
|
||||
} from 'matchstick-as/assembly/index';
|
||||
import { BigInt, Bytes } from '@graphprotocol/graph-ts';
|
||||
import '../generated/schema';
|
||||
import '../generated/FleekNFA/FleekNFA';
|
||||
import '../src/fleek-nfa';
|
||||
import './utils';
|
||||
import {
|
||||
NewBuild,
|
||||
NewTokenDescription,
|
||||
NewTokenENS,
|
||||
NewTokenExternalURL,
|
||||
NewTokenName,
|
||||
Transfer,
|
||||
} from '../generated/FleekNFA/FleekNFA';
|
||||
import {
|
||||
CONTRACT,
|
||||
createNewBuildEvent,
|
||||
createNewTokenDescriptionEvent,
|
||||
createNewTokenENSEvent,
|
||||
createNewTokenExternalURLEvent,
|
||||
createNewTokenNameEvent,
|
||||
createTransferEvent,
|
||||
handleNewBuilds,
|
||||
handleNewTokenDescriptions,
|
||||
handleNewTokenENSAddresses,
|
||||
handleNewTokenExternalURLs,
|
||||
handleNewTokenNames,
|
||||
handleTransfers,
|
||||
makeEventId,
|
||||
TOKEN_OWNER_ONE,
|
||||
TOKEN_OWNER_TWO,
|
||||
} from './utils';
|
||||
|
||||
describe('Describe entity assertions', () => {
|
||||
beforeAll(() => {
|
||||
// TRANSFERS
|
||||
let transfers: Transfer[] = [];
|
||||
transfers.push(
|
||||
createTransferEvent(0, CONTRACT, TOKEN_OWNER_ONE, BigInt.fromI32(0))
|
||||
);
|
||||
transfers.push(
|
||||
createTransferEvent(1, CONTRACT, TOKEN_OWNER_TWO, BigInt.fromI32(1))
|
||||
);
|
||||
transfers.push(
|
||||
createTransferEvent(2, CONTRACT, TOKEN_OWNER_ONE, BigInt.fromI32(2))
|
||||
);
|
||||
transfers.push(
|
||||
createTransferEvent(3, CONTRACT, TOKEN_OWNER_ONE, BigInt.fromI32(3))
|
||||
);
|
||||
transfers.push(
|
||||
createTransferEvent(
|
||||
4,
|
||||
TOKEN_OWNER_TWO,
|
||||
TOKEN_OWNER_ONE,
|
||||
BigInt.fromI32(1)
|
||||
)
|
||||
);
|
||||
transfers.push(
|
||||
createTransferEvent(5, CONTRACT, TOKEN_OWNER_TWO, BigInt.fromI32(4))
|
||||
);
|
||||
transfers.push(
|
||||
createTransferEvent(
|
||||
6,
|
||||
TOKEN_OWNER_ONE,
|
||||
TOKEN_OWNER_TWO,
|
||||
BigInt.fromI32(0)
|
||||
)
|
||||
);
|
||||
handleTransfers(transfers);
|
||||
|
||||
// NEW TOKEN NAME EVENTS
|
||||
let newTokenNames: NewTokenName[] = [];
|
||||
newTokenNames.push(
|
||||
createNewTokenNameEvent(
|
||||
0,
|
||||
BigInt.fromI32(0),
|
||||
'Token Zero New Name',
|
||||
TOKEN_OWNER_ONE
|
||||
)
|
||||
);
|
||||
newTokenNames.push(
|
||||
createNewTokenNameEvent(
|
||||
1,
|
||||
BigInt.fromI32(1),
|
||||
'Token One New Name',
|
||||
TOKEN_OWNER_TWO
|
||||
)
|
||||
);
|
||||
newTokenNames.push(
|
||||
createNewTokenNameEvent(
|
||||
2,
|
||||
BigInt.fromI32(2),
|
||||
'Token Two New Name',
|
||||
TOKEN_OWNER_ONE
|
||||
)
|
||||
);
|
||||
newTokenNames.push(
|
||||
createNewTokenNameEvent(
|
||||
3,
|
||||
BigInt.fromI32(3),
|
||||
'Token Three New Name',
|
||||
TOKEN_OWNER_ONE
|
||||
)
|
||||
);
|
||||
newTokenNames.push(
|
||||
createNewTokenNameEvent(
|
||||
4,
|
||||
BigInt.fromI32(4),
|
||||
'Token Four New Name',
|
||||
TOKEN_OWNER_TWO
|
||||
)
|
||||
);
|
||||
newTokenNames.push(
|
||||
createNewTokenNameEvent(
|
||||
5,
|
||||
BigInt.fromI32(0),
|
||||
'Token Zero New Name By New Owner',
|
||||
TOKEN_OWNER_TWO
|
||||
)
|
||||
);
|
||||
handleNewTokenNames(newTokenNames);
|
||||
|
||||
// New Token ENS Addresses
|
||||
let newENSAddresses: NewTokenENS[] = [];
|
||||
newENSAddresses.push(
|
||||
createNewTokenENSEvent(
|
||||
0,
|
||||
BigInt.fromI32(0),
|
||||
'New_Token_Zero_ENS',
|
||||
TOKEN_OWNER_ONE
|
||||
)
|
||||
);
|
||||
newENSAddresses.push(
|
||||
createNewTokenENSEvent(
|
||||
1,
|
||||
BigInt.fromI32(1),
|
||||
'New_Token_One_ENS',
|
||||
TOKEN_OWNER_TWO
|
||||
)
|
||||
);
|
||||
newENSAddresses.push(
|
||||
createNewTokenENSEvent(
|
||||
2,
|
||||
BigInt.fromI32(2),
|
||||
'New_Token_Two_ENS',
|
||||
TOKEN_OWNER_ONE
|
||||
)
|
||||
);
|
||||
newENSAddresses.push(
|
||||
createNewTokenENSEvent(
|
||||
3,
|
||||
BigInt.fromI32(3),
|
||||
'New_Token_Three_ENS',
|
||||
TOKEN_OWNER_ONE
|
||||
)
|
||||
);
|
||||
newENSAddresses.push(
|
||||
createNewTokenENSEvent(
|
||||
4,
|
||||
BigInt.fromI32(4),
|
||||
'New_Token_Four_ENS',
|
||||
TOKEN_OWNER_TWO
|
||||
)
|
||||
);
|
||||
newENSAddresses.push(
|
||||
createNewTokenENSEvent(
|
||||
5,
|
||||
BigInt.fromI32(5),
|
||||
'New_Token_Five_ENS',
|
||||
TOKEN_OWNER_TWO
|
||||
)
|
||||
);
|
||||
handleNewTokenENSAddresses(newENSAddresses);
|
||||
|
||||
// New Token Descriptions
|
||||
let newTokenDescriptions: NewTokenDescription[] = [];
|
||||
newTokenDescriptions.push(
|
||||
createNewTokenDescriptionEvent(
|
||||
0,
|
||||
BigInt.fromI32(0),
|
||||
'New Token Zero Description',
|
||||
TOKEN_OWNER_ONE
|
||||
)
|
||||
);
|
||||
newTokenDescriptions.push(
|
||||
createNewTokenDescriptionEvent(
|
||||
1,
|
||||
BigInt.fromI32(1),
|
||||
'New Token One Description',
|
||||
TOKEN_OWNER_TWO
|
||||
)
|
||||
);
|
||||
newTokenDescriptions.push(
|
||||
createNewTokenDescriptionEvent(
|
||||
2,
|
||||
BigInt.fromI32(2),
|
||||
'New Token Two Description',
|
||||
TOKEN_OWNER_ONE
|
||||
)
|
||||
);
|
||||
newTokenDescriptions.push(
|
||||
createNewTokenDescriptionEvent(
|
||||
3,
|
||||
BigInt.fromI32(3),
|
||||
'New Token Three Description',
|
||||
TOKEN_OWNER_ONE
|
||||
)
|
||||
);
|
||||
newTokenDescriptions.push(
|
||||
createNewTokenDescriptionEvent(
|
||||
4,
|
||||
BigInt.fromI32(4),
|
||||
'New Token Four Description',
|
||||
TOKEN_OWNER_TWO
|
||||
)
|
||||
);
|
||||
newTokenDescriptions.push(
|
||||
createNewTokenDescriptionEvent(
|
||||
5,
|
||||
BigInt.fromI32(5),
|
||||
'New Token Five Description By New Owner',
|
||||
TOKEN_OWNER_TWO
|
||||
)
|
||||
);
|
||||
handleNewTokenDescriptions(newTokenDescriptions);
|
||||
|
||||
// New Token External URLs
|
||||
let newTokenExternalURLs: NewTokenExternalURL[] = [];
|
||||
newTokenExternalURLs.push(
|
||||
createNewTokenExternalURLEvent(
|
||||
0,
|
||||
BigInt.fromI32(0),
|
||||
'https://0_external.url',
|
||||
TOKEN_OWNER_ONE
|
||||
)
|
||||
);
|
||||
newTokenExternalURLs.push(
|
||||
createNewTokenExternalURLEvent(
|
||||
1,
|
||||
BigInt.fromI32(1),
|
||||
'https://1_external.url',
|
||||
TOKEN_OWNER_TWO
|
||||
)
|
||||
);
|
||||
newTokenExternalURLs.push(
|
||||
createNewTokenExternalURLEvent(
|
||||
2,
|
||||
BigInt.fromI32(2),
|
||||
'https://2_external.url',
|
||||
TOKEN_OWNER_ONE
|
||||
)
|
||||
);
|
||||
newTokenExternalURLs.push(
|
||||
createNewTokenExternalURLEvent(
|
||||
3,
|
||||
BigInt.fromI32(3),
|
||||
'https://3_external.url',
|
||||
TOKEN_OWNER_ONE
|
||||
)
|
||||
);
|
||||
newTokenExternalURLs.push(
|
||||
createNewTokenExternalURLEvent(
|
||||
4,
|
||||
BigInt.fromI32(4),
|
||||
'https://4_external.url',
|
||||
TOKEN_OWNER_TWO
|
||||
)
|
||||
);
|
||||
newTokenExternalURLs.push(
|
||||
createNewTokenExternalURLEvent(
|
||||
5,
|
||||
BigInt.fromI32(5),
|
||||
'https://5_external.url',
|
||||
TOKEN_OWNER_TWO
|
||||
)
|
||||
);
|
||||
handleNewTokenExternalURLs(newTokenExternalURLs);
|
||||
|
||||
// New Token External URLs
|
||||
let newBuilds: NewBuild[] = [];
|
||||
newBuilds.push(
|
||||
createNewBuildEvent(0, BigInt.fromI32(0), 'hash0_0', TOKEN_OWNER_ONE)
|
||||
);
|
||||
newBuilds.push(
|
||||
createNewBuildEvent(1, BigInt.fromI32(1), 'hash1_0', TOKEN_OWNER_TWO)
|
||||
);
|
||||
newBuilds.push(
|
||||
createNewBuildEvent(2, BigInt.fromI32(2), 'hash2_0', TOKEN_OWNER_ONE)
|
||||
);
|
||||
newBuilds.push(
|
||||
createNewBuildEvent(3, BigInt.fromI32(3), 'hash3_0', TOKEN_OWNER_ONE)
|
||||
);
|
||||
newBuilds.push(
|
||||
createNewBuildEvent(4, BigInt.fromI32(4), 'hash4_0', TOKEN_OWNER_TWO)
|
||||
);
|
||||
newBuilds.push(
|
||||
createNewBuildEvent(5, BigInt.fromI32(5), 'hash5_0', TOKEN_OWNER_TWO)
|
||||
);
|
||||
handleNewBuilds(newBuilds);
|
||||
|
||||
logStore();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
clearStore();
|
||||
});
|
||||
|
||||
describe('Transfers', () => {
|
||||
test('Check the number of transfers to be valid', () => {
|
||||
assert.entityCount('Transfer', 7);
|
||||
});
|
||||
test('Check the `from` and `to` fields of each transfer to be equal to expected values', () => {
|
||||
assert.fieldEquals(
|
||||
'Transfer',
|
||||
makeEventId(0),
|
||||
'to',
|
||||
'0x2000000000000000000000000000000000000002'
|
||||
);
|
||||
assert.fieldEquals(
|
||||
'Transfer',
|
||||
makeEventId(1),
|
||||
'to',
|
||||
'0x3000000000000000000000000000000000000003'
|
||||
);
|
||||
assert.fieldEquals(
|
||||
'Transfer',
|
||||
makeEventId(2),
|
||||
'to',
|
||||
'0x2000000000000000000000000000000000000002'
|
||||
);
|
||||
assert.fieldEquals(
|
||||
'Transfer',
|
||||
makeEventId(3),
|
||||
'to',
|
||||
'0x2000000000000000000000000000000000000002'
|
||||
);
|
||||
assert.fieldEquals(
|
||||
'Transfer',
|
||||
makeEventId(4),
|
||||
'to',
|
||||
'0x2000000000000000000000000000000000000002'
|
||||
);
|
||||
assert.fieldEquals(
|
||||
'Transfer',
|
||||
makeEventId(5),
|
||||
'to',
|
||||
'0x3000000000000000000000000000000000000003'
|
||||
);
|
||||
assert.fieldEquals(
|
||||
'Transfer',
|
||||
makeEventId(6),
|
||||
'to',
|
||||
'0x3000000000000000000000000000000000000003'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('New Token Name Events', () => {
|
||||
test('Check the number of NewTokenName to be valid', () => {
|
||||
assert.entityCount('NewTokenName', 6);
|
||||
});
|
||||
test('Check the `name` and `triggeredBy` fields of each new token name event to be equal to expected values', () => {
|
||||
assert.fieldEquals(
|
||||
'NewTokenName',
|
||||
makeEventId(0),
|
||||
'name',
|
||||
'Token Zero New Name'
|
||||
);
|
||||
assert.fieldEquals(
|
||||
'NewTokenName',
|
||||
makeEventId(1),
|
||||
'name',
|
||||
'Token One New Name'
|
||||
);
|
||||
assert.fieldEquals(
|
||||
'NewTokenName',
|
||||
makeEventId(2),
|
||||
'name',
|
||||
'Token Two New Name'
|
||||
);
|
||||
assert.fieldEquals(
|
||||
'NewTokenName',
|
||||
makeEventId(3),
|
||||
'name',
|
||||
'Token Three New Name'
|
||||
);
|
||||
assert.fieldEquals(
|
||||
'NewTokenName',
|
||||
makeEventId(4),
|
||||
'name',
|
||||
'Token Four New Name'
|
||||
);
|
||||
assert.fieldEquals(
|
||||
'NewTokenName',
|
||||
makeEventId(5),
|
||||
'name',
|
||||
'Token Zero New Name By New Owner'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('New Token External URL Events', () => {
|
||||
test('Check the number of newTokenExternalURl events to be valid', () => {
|
||||
assert.entityCount('NewTokenExternalURL', 6);
|
||||
});
|
||||
test('Check the `description` and `triggeredBy` fields of each new token name event to be equal to expected values', () => {
|
||||
assert.fieldEquals(
|
||||
'NewTokenExternalURL',
|
||||
makeEventId(0),
|
||||
'externalURL',
|
||||
'https://0_external.url'
|
||||
);
|
||||
assert.fieldEquals(
|
||||
'NewTokenExternalURL',
|
||||
makeEventId(1),
|
||||
'externalURL',
|
||||
'https://1_external.url'
|
||||
);
|
||||
assert.fieldEquals(
|
||||
'NewTokenExternalURL',
|
||||
makeEventId(2),
|
||||
'externalURL',
|
||||
'https://2_external.url'
|
||||
);
|
||||
assert.fieldEquals(
|
||||
'NewTokenExternalURL',
|
||||
makeEventId(3),
|
||||
'externalURL',
|
||||
'https://3_external.url'
|
||||
);
|
||||
assert.fieldEquals(
|
||||
'NewTokenExternalURL',
|
||||
makeEventId(4),
|
||||
'externalURL',
|
||||
'https://4_external.url'
|
||||
);
|
||||
assert.fieldEquals(
|
||||
'NewTokenExternalURL',
|
||||
makeEventId(5),
|
||||
'externalURL',
|
||||
'https://5_external.url'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('New Token Description Events', () => {
|
||||
test('Check the number of NewTokenDescription events to be valid', () => {
|
||||
assert.entityCount('NewTokenDescription', 6);
|
||||
});
|
||||
test('Check the `description` and `triggeredBy` fields of each new token name event to be equal to expected values', () => {
|
||||
assert.fieldEquals(
|
||||
'NewTokenDescription',
|
||||
makeEventId(0),
|
||||
'description',
|
||||
'New Token Zero Description'
|
||||
);
|
||||
assert.fieldEquals(
|
||||
'NewTokenDescription',
|
||||
makeEventId(1),
|
||||
'description',
|
||||
'New Token One Description'
|
||||
);
|
||||
assert.fieldEquals(
|
||||
'NewTokenDescription',
|
||||
makeEventId(2),
|
||||
'description',
|
||||
'New Token Two Description'
|
||||
);
|
||||
assert.fieldEquals(
|
||||
'NewTokenDescription',
|
||||
makeEventId(3),
|
||||
'description',
|
||||
'New Token Three Description'
|
||||
);
|
||||
assert.fieldEquals(
|
||||
'NewTokenDescription',
|
||||
makeEventId(4),
|
||||
'description',
|
||||
'New Token Four Description'
|
||||
);
|
||||
assert.fieldEquals(
|
||||
'NewTokenDescription',
|
||||
makeEventId(5),
|
||||
'description',
|
||||
'New Token Five Description By New Owner'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"version": "0.5.4",
|
||||
"timestamp": 1677510060006
|
||||
}
|
||||
|
|
@ -0,0 +1,222 @@
|
|||
import { newMockEvent } from 'matchstick-as';
|
||||
import { ethereum, Address, BigInt, Bytes } from '@graphprotocol/graph-ts';
|
||||
import {
|
||||
Approval as ApprovalEvent,
|
||||
ApprovalForAll as ApprovalForAllEvent,
|
||||
Transfer as TransferEvent,
|
||||
NewMint as NewMintEvent
|
||||
} from '../../../generated/FleekNFA/FleekNFA';
|
||||
import {
|
||||
handleApproval,
|
||||
handleApprovalForAll,
|
||||
handleNewMint,
|
||||
handleTransfer,
|
||||
} from '../../../src/fleek-nfa';
|
||||
|
||||
export function createApprovalEvent(
|
||||
event_count: i32,
|
||||
owner: Address,
|
||||
approved: Address,
|
||||
tokenId: BigInt
|
||||
): ApprovalEvent {
|
||||
let approvalEvent = changetype<ApprovalEvent>(newMockEvent());
|
||||
|
||||
approvalEvent.parameters = new Array();
|
||||
|
||||
approvalEvent.parameters.push(
|
||||
new ethereum.EventParam('owner', ethereum.Value.fromAddress(owner))
|
||||
);
|
||||
approvalEvent.parameters.push(
|
||||
new ethereum.EventParam('approved', ethereum.Value.fromAddress(approved))
|
||||
);
|
||||
approvalEvent.parameters.push(
|
||||
new ethereum.EventParam(
|
||||
'tokenId',
|
||||
ethereum.Value.fromUnsignedBigInt(tokenId)
|
||||
)
|
||||
);
|
||||
|
||||
approvalEvent.transaction.hash = Bytes.fromI32(event_count);
|
||||
approvalEvent.logIndex = new BigInt(event_count);
|
||||
|
||||
return approvalEvent;
|
||||
}
|
||||
|
||||
export function createApprovalForAllEvent(
|
||||
event_count: i32,
|
||||
owner: Address,
|
||||
operator: Address,
|
||||
approved: boolean
|
||||
): ApprovalForAllEvent {
|
||||
let approvalForAllEvent = changetype<ApprovalForAllEvent>(newMockEvent());
|
||||
|
||||
approvalForAllEvent.parameters = new Array();
|
||||
|
||||
approvalForAllEvent.parameters.push(
|
||||
new ethereum.EventParam('owner', ethereum.Value.fromAddress(owner))
|
||||
);
|
||||
approvalForAllEvent.parameters.push(
|
||||
new ethereum.EventParam('operator', ethereum.Value.fromAddress(operator))
|
||||
);
|
||||
approvalForAllEvent.parameters.push(
|
||||
new ethereum.EventParam('approved', ethereum.Value.fromBoolean(approved))
|
||||
);
|
||||
|
||||
approvalForAllEvent.transaction.hash = Bytes.fromI32(event_count);
|
||||
approvalForAllEvent.logIndex = new BigInt(event_count);
|
||||
|
||||
return approvalForAllEvent;
|
||||
}
|
||||
|
||||
export function createTransferEvent(
|
||||
event_count: i32,
|
||||
from: Address,
|
||||
to: Address,
|
||||
tokenId: BigInt
|
||||
): TransferEvent {
|
||||
let transferEvent = changetype<TransferEvent>(newMockEvent());
|
||||
|
||||
transferEvent.parameters = new Array();
|
||||
|
||||
transferEvent.parameters.push(
|
||||
new ethereum.EventParam('from', ethereum.Value.fromAddress(from))
|
||||
);
|
||||
transferEvent.parameters.push(
|
||||
new ethereum.EventParam('to', ethereum.Value.fromAddress(to))
|
||||
);
|
||||
transferEvent.parameters.push(
|
||||
new ethereum.EventParam(
|
||||
'tokenId',
|
||||
ethereum.Value.fromUnsignedBigInt(tokenId)
|
||||
)
|
||||
);
|
||||
|
||||
transferEvent.transaction.hash = Bytes.fromI32(event_count);
|
||||
transferEvent.logIndex = new BigInt(event_count);
|
||||
|
||||
return transferEvent;
|
||||
}
|
||||
|
||||
export function createNewMintEvent(
|
||||
event_count: i32,
|
||||
to: Address,
|
||||
tokenId: BigInt
|
||||
): NewMintEvent {
|
||||
let newMintEvent = changetype<NewMintEvent>(newMockEvent());
|
||||
|
||||
newMintEvent.parameters = new Array();
|
||||
|
||||
newMintEvent.parameters.push(
|
||||
new ethereum.EventParam(
|
||||
'tokenId',
|
||||
ethereum.Value.fromUnsignedBigInt(tokenId)
|
||||
)
|
||||
);
|
||||
newMintEvent.parameters.push(
|
||||
new ethereum.EventParam(
|
||||
'name',
|
||||
ethereum.Value.fromString('name')
|
||||
)
|
||||
);
|
||||
newMintEvent.parameters.push(
|
||||
new ethereum.EventParam(
|
||||
'description',
|
||||
ethereum.Value.fromString('description')
|
||||
)
|
||||
);
|
||||
newMintEvent.parameters.push(
|
||||
new ethereum.EventParam(
|
||||
'externalURL',
|
||||
ethereum.Value.fromString('externalurl')
|
||||
)
|
||||
);
|
||||
newMintEvent.parameters.push(
|
||||
new ethereum.EventParam(
|
||||
'ENS',
|
||||
ethereum.Value.fromString('ens')
|
||||
)
|
||||
);
|
||||
newMintEvent.parameters.push(
|
||||
new ethereum.EventParam(
|
||||
'commitHash',
|
||||
ethereum.Value.fromString('hash')
|
||||
)
|
||||
);
|
||||
newMintEvent.parameters.push(
|
||||
new ethereum.EventParam(
|
||||
'gitRepository',
|
||||
ethereum.Value.fromString('repo')
|
||||
)
|
||||
);
|
||||
newMintEvent.parameters.push(
|
||||
new ethereum.EventParam(
|
||||
'logo',
|
||||
ethereum.Value.fromString('logo')
|
||||
)
|
||||
);
|
||||
newMintEvent.parameters.push(
|
||||
new ethereum.EventParam(
|
||||
'color',
|
||||
ethereum.Value.fromI32(1234)
|
||||
)
|
||||
);
|
||||
newMintEvent.parameters.push(
|
||||
new ethereum.EventParam(
|
||||
'accessPointAutoApproval',
|
||||
ethereum.Value.fromBoolean(true)
|
||||
)
|
||||
);
|
||||
newMintEvent.parameters.push(
|
||||
new ethereum.EventParam('minter', ethereum.Value.fromAddress(to))
|
||||
);
|
||||
newMintEvent.parameters.push(
|
||||
new ethereum.EventParam('owner', ethereum.Value.fromAddress(to))
|
||||
);
|
||||
|
||||
newMintEvent.transaction.hash = Bytes.fromI32(event_count);
|
||||
newMintEvent.logIndex = new BigInt(event_count);
|
||||
|
||||
return newMintEvent;
|
||||
}
|
||||
|
||||
|
||||
export const CONTRACT: Address = Address.fromString(
|
||||
'0x0000000000000000000000000000000000000000'
|
||||
);
|
||||
export const CONTRACT_OWNER: Address = Address.fromString(
|
||||
'0x1000000000000000000000000000000000000001'
|
||||
);
|
||||
export const TOKEN_OWNER_ONE: Address = Address.fromString(
|
||||
'0x2000000000000000000000000000000000000002'
|
||||
);
|
||||
export const TOKEN_OWNER_TWO: Address = Address.fromString(
|
||||
'0x3000000000000000000000000000000000000003'
|
||||
);
|
||||
|
||||
export function handleTransfers(events: TransferEvent[]): void {
|
||||
events.forEach((event) => {
|
||||
handleTransfer(event);
|
||||
});
|
||||
}
|
||||
|
||||
export function handleApprovals(events: ApprovalEvent[]): void {
|
||||
events.forEach((event) => {
|
||||
handleApproval(event);
|
||||
});
|
||||
}
|
||||
|
||||
export function handleNewMints(events: NewMintEvent[]): void {
|
||||
events.forEach((event) => {
|
||||
handleNewMint(event);
|
||||
});
|
||||
}
|
||||
|
||||
export function handleApprovalForAlls(events: ApprovalForAllEvent[]): void {
|
||||
events.forEach((event) => {
|
||||
handleApprovalForAll(event);
|
||||
});
|
||||
}
|
||||
|
||||
export function makeEventId(id: i32): string {
|
||||
return Bytes.fromI32(id).toHexString() + '00000000';
|
||||
}
|
||||
|
|
@ -0,0 +1,135 @@
|
|||
import {
|
||||
assert,
|
||||
describe,
|
||||
test,
|
||||
clearStore,
|
||||
beforeAll,
|
||||
afterAll,
|
||||
logStore,
|
||||
log,
|
||||
} from 'matchstick-as/assembly/index';
|
||||
import { BigInt } from '@graphprotocol/graph-ts';
|
||||
import { CONTRACT, createNewMintEvent, createTransferEvent, handleNewMints, handleTransfers, makeEventId, TOKEN_OWNER_ONE, TOKEN_OWNER_TWO } from './helpers/utils';
|
||||
import { NewMint, Transfer } from '../../generated/FleekNFA/FleekNFA';
|
||||
|
||||
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))
|
||||
);
|
||||
handleNewMints(newMints);
|
||||
// TRANSFERS
|
||||
let transfers: Transfer[] = [];
|
||||
transfers.push(
|
||||
createTransferEvent(0, CONTRACT, TOKEN_OWNER_ONE, BigInt.fromI32(0))
|
||||
);
|
||||
transfers.push(
|
||||
createTransferEvent(1, CONTRACT, TOKEN_OWNER_TWO, BigInt.fromI32(1))
|
||||
);
|
||||
transfers.push(
|
||||
createTransferEvent(2, CONTRACT, TOKEN_OWNER_ONE, BigInt.fromI32(2))
|
||||
);
|
||||
transfers.push(
|
||||
createTransferEvent(3, CONTRACT, TOKEN_OWNER_ONE, BigInt.fromI32(3))
|
||||
);
|
||||
transfers.push(
|
||||
createTransferEvent(
|
||||
4,
|
||||
TOKEN_OWNER_TWO,
|
||||
TOKEN_OWNER_ONE,
|
||||
BigInt.fromI32(1)
|
||||
)
|
||||
);
|
||||
transfers.push(
|
||||
createTransferEvent(5, CONTRACT, TOKEN_OWNER_TWO, BigInt.fromI32(4))
|
||||
);
|
||||
transfers.push(
|
||||
createTransferEvent(
|
||||
6,
|
||||
TOKEN_OWNER_ONE,
|
||||
TOKEN_OWNER_TWO,
|
||||
BigInt.fromI32(0)
|
||||
)
|
||||
);
|
||||
handleTransfers(transfers);
|
||||
//logStore();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
clearStore();
|
||||
});
|
||||
|
||||
describe('Transfers', () => {
|
||||
test('Check the number of transfers to be valid', () => {
|
||||
assert.entityCount('Transfer', 7);
|
||||
});
|
||||
test('Check the `from` and `to` fields of each transfer to be equal to expected values', () => {
|
||||
assert.fieldEquals(
|
||||
'Transfer',
|
||||
makeEventId(0),
|
||||
'to',
|
||||
'0x2000000000000000000000000000000000000002'
|
||||
);
|
||||
assert.fieldEquals(
|
||||
'Transfer',
|
||||
makeEventId(1),
|
||||
'to',
|
||||
'0x3000000000000000000000000000000000000003'
|
||||
);
|
||||
assert.fieldEquals(
|
||||
'Transfer',
|
||||
makeEventId(2),
|
||||
'to',
|
||||
'0x2000000000000000000000000000000000000002'
|
||||
);
|
||||
assert.fieldEquals(
|
||||
'Transfer',
|
||||
makeEventId(3),
|
||||
'to',
|
||||
'0x2000000000000000000000000000000000000002'
|
||||
);
|
||||
assert.fieldEquals(
|
||||
'Transfer',
|
||||
makeEventId(4),
|
||||
'to',
|
||||
'0x2000000000000000000000000000000000000002'
|
||||
);
|
||||
assert.fieldEquals(
|
||||
'Transfer',
|
||||
makeEventId(5),
|
||||
'to',
|
||||
'0x3000000000000000000000000000000000000003'
|
||||
);
|
||||
assert.fieldEquals(
|
||||
'Transfer',
|
||||
makeEventId(6),
|
||||
'to',
|
||||
'0x3000000000000000000000000000000000000003'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Owner Assertions', () => {
|
||||
test('Check the number of owners to be valid', () => {
|
||||
assert.entityCount('Owner', 2);
|
||||
});
|
||||
test('Check the existence of owners in store', () => {
|
||||
assert.fieldEquals('Owner', TOKEN_OWNER_ONE.toHexString(), 'id', TOKEN_OWNER_ONE.toHexString());
|
||||
assert.fieldEquals('Owner', TOKEN_OWNER_TWO.toHexString(), 'id', TOKEN_OWNER_TWO.toHexString());
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,107 @@
|
|||
import {
|
||||
assert,
|
||||
describe,
|
||||
test,
|
||||
clearStore,
|
||||
beforeAll,
|
||||
afterAll,
|
||||
logStore,
|
||||
log,
|
||||
} from 'matchstick-as/assembly/index';
|
||||
import { BigInt, Bytes } from '@graphprotocol/graph-ts';
|
||||
import { CONTRACT, createTransferEvent, handleTransfers, makeEventId, TOKEN_OWNER_ONE, TOKEN_OWNER_TWO } from './helpers/utils';
|
||||
import { Transfer } from '../../generated/FleekNFA/FleekNFA';
|
||||
|
||||
describe('Transfer tests', () => {
|
||||
beforeAll(() => {
|
||||
// TRANSFERS
|
||||
let transfers: Transfer[] = [];
|
||||
transfers.push(
|
||||
createTransferEvent(0, CONTRACT, TOKEN_OWNER_ONE, BigInt.fromI32(0))
|
||||
);
|
||||
transfers.push(
|
||||
createTransferEvent(1, CONTRACT, TOKEN_OWNER_TWO, BigInt.fromI32(1))
|
||||
);
|
||||
transfers.push(
|
||||
createTransferEvent(2, CONTRACT, TOKEN_OWNER_ONE, BigInt.fromI32(2))
|
||||
);
|
||||
transfers.push(
|
||||
createTransferEvent(3, CONTRACT, TOKEN_OWNER_ONE, BigInt.fromI32(3))
|
||||
);
|
||||
transfers.push(
|
||||
createTransferEvent(
|
||||
4,
|
||||
TOKEN_OWNER_TWO,
|
||||
TOKEN_OWNER_ONE,
|
||||
BigInt.fromI32(1)
|
||||
)
|
||||
);
|
||||
transfers.push(
|
||||
createTransferEvent(5, CONTRACT, TOKEN_OWNER_TWO, BigInt.fromI32(4))
|
||||
);
|
||||
transfers.push(
|
||||
createTransferEvent(
|
||||
6,
|
||||
TOKEN_OWNER_ONE,
|
||||
TOKEN_OWNER_TWO,
|
||||
BigInt.fromI32(0)
|
||||
)
|
||||
);
|
||||
handleTransfers(transfers);
|
||||
// logStore();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
clearStore();
|
||||
});
|
||||
|
||||
describe('Transfers', () => {
|
||||
test('Check the number of transfers to be valid', () => {
|
||||
assert.entityCount('Transfer', 7);
|
||||
});
|
||||
test('Check the `from` and `to` fields of each transfer to be equal to expected values', () => {
|
||||
assert.fieldEquals(
|
||||
'Transfer',
|
||||
makeEventId(0),
|
||||
'to',
|
||||
'0x2000000000000000000000000000000000000002'
|
||||
);
|
||||
assert.fieldEquals(
|
||||
'Transfer',
|
||||
makeEventId(1),
|
||||
'to',
|
||||
'0x3000000000000000000000000000000000000003'
|
||||
);
|
||||
assert.fieldEquals(
|
||||
'Transfer',
|
||||
makeEventId(2),
|
||||
'to',
|
||||
'0x2000000000000000000000000000000000000002'
|
||||
);
|
||||
assert.fieldEquals(
|
||||
'Transfer',
|
||||
makeEventId(3),
|
||||
'to',
|
||||
'0x2000000000000000000000000000000000000002'
|
||||
);
|
||||
assert.fieldEquals(
|
||||
'Transfer',
|
||||
makeEventId(4),
|
||||
'to',
|
||||
'0x2000000000000000000000000000000000000002'
|
||||
);
|
||||
assert.fieldEquals(
|
||||
'Transfer',
|
||||
makeEventId(5),
|
||||
'to',
|
||||
'0x3000000000000000000000000000000000000003'
|
||||
);
|
||||
assert.fieldEquals(
|
||||
'Transfer',
|
||||
makeEventId(6),
|
||||
'to',
|
||||
'0x3000000000000000000000000000000000000003'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -1,537 +0,0 @@
|
|||
import { newMockEvent } from 'matchstick-as';
|
||||
import { ethereum, Address, BigInt, Bytes } from '@graphprotocol/graph-ts';
|
||||
import {
|
||||
Approval as ApprovalEvent,
|
||||
ApprovalForAll as ApprovalForAllEvent,
|
||||
CollectionRoleGranted as CollectionRoleGrantedEvent,
|
||||
CollectionRoleRevoked as CollectionRoleRevokedEvent,
|
||||
NewBuild as NewBuildEvent,
|
||||
NewTokenDescription as NewTokenDescriptionEvent,
|
||||
NewTokenENS as NewTokenENSEvent,
|
||||
NewTokenExternalURL as NewTokenExternalURLEvent,
|
||||
NewTokenLogo as NewTokenLogoEvent,
|
||||
NewTokenName as NewTokenNameEvent,
|
||||
TokenRoleGranted as TokenRoleGrantedEvent,
|
||||
TokenRoleRevoked as TokenRoleRevokedEvent,
|
||||
Transfer as TransferEvent,
|
||||
} from '../generated/FleekNFA/FleekNFA';
|
||||
import {
|
||||
handleApproval,
|
||||
handleApprovalForAll,
|
||||
handleCollectionRoleGranted,
|
||||
handleCollectionRoleRevoked,
|
||||
handleNewBuild,
|
||||
handleNewTokenDescription,
|
||||
handleNewTokenENS,
|
||||
handleNewTokenExternalURL,
|
||||
handleNewTokenLogo,
|
||||
handleNewTokenName,
|
||||
handleTokenRoleGranted,
|
||||
handleTokenRoleRevoked,
|
||||
handleTransfer,
|
||||
} from '../src/fleek-nfa';
|
||||
|
||||
export function createApprovalEvent(
|
||||
event_count: i32,
|
||||
owner: Address,
|
||||
approved: Address,
|
||||
tokenId: BigInt
|
||||
): ApprovalEvent {
|
||||
let approvalEvent = changetype<ApprovalEvent>(newMockEvent());
|
||||
|
||||
approvalEvent.parameters = new Array();
|
||||
|
||||
approvalEvent.parameters.push(
|
||||
new ethereum.EventParam('owner', ethereum.Value.fromAddress(owner))
|
||||
);
|
||||
approvalEvent.parameters.push(
|
||||
new ethereum.EventParam('approved', ethereum.Value.fromAddress(approved))
|
||||
);
|
||||
approvalEvent.parameters.push(
|
||||
new ethereum.EventParam(
|
||||
'tokenId',
|
||||
ethereum.Value.fromUnsignedBigInt(tokenId)
|
||||
)
|
||||
);
|
||||
|
||||
approvalEvent.transaction.hash = Bytes.fromI32(event_count);
|
||||
approvalEvent.logIndex = new BigInt(event_count);
|
||||
|
||||
return approvalEvent;
|
||||
}
|
||||
|
||||
export function createApprovalForAllEvent(
|
||||
event_count: i32,
|
||||
owner: Address,
|
||||
operator: Address,
|
||||
approved: boolean
|
||||
): ApprovalForAllEvent {
|
||||
let approvalForAllEvent = changetype<ApprovalForAllEvent>(newMockEvent());
|
||||
|
||||
approvalForAllEvent.parameters = new Array();
|
||||
|
||||
approvalForAllEvent.parameters.push(
|
||||
new ethereum.EventParam('owner', ethereum.Value.fromAddress(owner))
|
||||
);
|
||||
approvalForAllEvent.parameters.push(
|
||||
new ethereum.EventParam('operator', ethereum.Value.fromAddress(operator))
|
||||
);
|
||||
approvalForAllEvent.parameters.push(
|
||||
new ethereum.EventParam('approved', ethereum.Value.fromBoolean(approved))
|
||||
);
|
||||
|
||||
approvalForAllEvent.transaction.hash = Bytes.fromI32(event_count);
|
||||
approvalForAllEvent.logIndex = new BigInt(event_count);
|
||||
|
||||
return approvalForAllEvent;
|
||||
}
|
||||
|
||||
export function createCollectionRoleGrantedEvent(
|
||||
event_count: i32,
|
||||
role: i32,
|
||||
toAddress: Address,
|
||||
byAddress: Address
|
||||
): CollectionRoleGrantedEvent {
|
||||
let collectionRoleGrantedEvent = changetype<CollectionRoleGrantedEvent>(
|
||||
newMockEvent()
|
||||
);
|
||||
|
||||
collectionRoleGrantedEvent.parameters = new Array();
|
||||
|
||||
collectionRoleGrantedEvent.parameters.push(
|
||||
new ethereum.EventParam(
|
||||
'role',
|
||||
ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(role))
|
||||
)
|
||||
);
|
||||
collectionRoleGrantedEvent.parameters.push(
|
||||
new ethereum.EventParam('toAddress', ethereum.Value.fromAddress(toAddress))
|
||||
);
|
||||
collectionRoleGrantedEvent.parameters.push(
|
||||
new ethereum.EventParam('byAddress', ethereum.Value.fromAddress(byAddress))
|
||||
);
|
||||
|
||||
collectionRoleGrantedEvent.transaction.hash = Bytes.fromI32(event_count);
|
||||
collectionRoleGrantedEvent.logIndex = new BigInt(event_count);
|
||||
|
||||
return collectionRoleGrantedEvent;
|
||||
}
|
||||
|
||||
export function createCollectionRoleRevokedEvent(
|
||||
event_count: i32,
|
||||
role: i32,
|
||||
toAddress: Address,
|
||||
byAddress: Address
|
||||
): CollectionRoleRevokedEvent {
|
||||
let collectionRoleRevokedEvent = changetype<CollectionRoleRevokedEvent>(
|
||||
newMockEvent()
|
||||
);
|
||||
|
||||
collectionRoleRevokedEvent.parameters = new Array();
|
||||
|
||||
collectionRoleRevokedEvent.parameters.push(
|
||||
new ethereum.EventParam(
|
||||
'role',
|
||||
ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(role))
|
||||
)
|
||||
);
|
||||
collectionRoleRevokedEvent.parameters.push(
|
||||
new ethereum.EventParam('toAddress', ethereum.Value.fromAddress(toAddress))
|
||||
);
|
||||
collectionRoleRevokedEvent.parameters.push(
|
||||
new ethereum.EventParam('byAddress', ethereum.Value.fromAddress(byAddress))
|
||||
);
|
||||
|
||||
collectionRoleRevokedEvent.transaction.hash = Bytes.fromI32(event_count);
|
||||
collectionRoleRevokedEvent.logIndex = new BigInt(event_count);
|
||||
|
||||
return collectionRoleRevokedEvent;
|
||||
}
|
||||
|
||||
export function createNewBuildEvent(
|
||||
event_count: i32,
|
||||
token: BigInt,
|
||||
commitHash: string,
|
||||
triggeredBy: Address
|
||||
): NewBuildEvent {
|
||||
let newBuildEvent = changetype<NewBuildEvent>(newMockEvent());
|
||||
|
||||
newBuildEvent.parameters = new Array();
|
||||
|
||||
newBuildEvent.parameters.push(
|
||||
new ethereum.EventParam('token', ethereum.Value.fromUnsignedBigInt(token))
|
||||
);
|
||||
newBuildEvent.parameters.push(
|
||||
new ethereum.EventParam('commitHash', ethereum.Value.fromString(commitHash))
|
||||
);
|
||||
newBuildEvent.parameters.push(
|
||||
new ethereum.EventParam(
|
||||
'triggeredBy',
|
||||
ethereum.Value.fromAddress(triggeredBy)
|
||||
)
|
||||
);
|
||||
|
||||
newBuildEvent.transaction.hash = Bytes.fromI32(event_count);
|
||||
newBuildEvent.logIndex = new BigInt(event_count);
|
||||
|
||||
return newBuildEvent;
|
||||
}
|
||||
|
||||
export function createNewTokenDescriptionEvent(
|
||||
event_count: i32,
|
||||
token: BigInt,
|
||||
description: string,
|
||||
triggeredBy: Address
|
||||
): NewTokenDescriptionEvent {
|
||||
let newTokenDescriptionEvent = changetype<NewTokenDescriptionEvent>(
|
||||
newMockEvent()
|
||||
);
|
||||
|
||||
newTokenDescriptionEvent.parameters = new Array();
|
||||
|
||||
newTokenDescriptionEvent.parameters.push(
|
||||
new ethereum.EventParam('token', ethereum.Value.fromUnsignedBigInt(token))
|
||||
);
|
||||
newTokenDescriptionEvent.parameters.push(
|
||||
new ethereum.EventParam(
|
||||
'description',
|
||||
ethereum.Value.fromString(description)
|
||||
)
|
||||
);
|
||||
newTokenDescriptionEvent.parameters.push(
|
||||
new ethereum.EventParam(
|
||||
'triggeredBy',
|
||||
ethereum.Value.fromAddress(triggeredBy)
|
||||
)
|
||||
);
|
||||
|
||||
newTokenDescriptionEvent.transaction.hash = Bytes.fromI32(event_count);
|
||||
newTokenDescriptionEvent.logIndex = new BigInt(event_count);
|
||||
|
||||
return newTokenDescriptionEvent;
|
||||
}
|
||||
|
||||
export function createNewTokenENSEvent(
|
||||
event_count: i32,
|
||||
token: BigInt,
|
||||
ENS: string,
|
||||
triggeredBy: Address
|
||||
): NewTokenENSEvent {
|
||||
let newTokenEnsEvent = changetype<NewTokenENSEvent>(newMockEvent());
|
||||
|
||||
newTokenEnsEvent.parameters = new Array();
|
||||
|
||||
newTokenEnsEvent.parameters.push(
|
||||
new ethereum.EventParam('token', ethereum.Value.fromUnsignedBigInt(token))
|
||||
);
|
||||
newTokenEnsEvent.parameters.push(
|
||||
new ethereum.EventParam('ENS', ethereum.Value.fromString(ENS))
|
||||
);
|
||||
newTokenEnsEvent.parameters.push(
|
||||
new ethereum.EventParam(
|
||||
'triggeredBy',
|
||||
ethereum.Value.fromAddress(triggeredBy)
|
||||
)
|
||||
);
|
||||
|
||||
newTokenEnsEvent.transaction.hash = Bytes.fromI32(event_count);
|
||||
newTokenEnsEvent.logIndex = new BigInt(event_count);
|
||||
|
||||
return newTokenEnsEvent;
|
||||
}
|
||||
|
||||
export function createNewTokenExternalURLEvent(
|
||||
event_count: i32,
|
||||
token: BigInt,
|
||||
externalURL: string,
|
||||
triggeredBy: Address
|
||||
): NewTokenExternalURLEvent {
|
||||
let newTokenExternalUrlEvent = changetype<NewTokenExternalURLEvent>(
|
||||
newMockEvent()
|
||||
);
|
||||
|
||||
newTokenExternalUrlEvent.parameters = new Array();
|
||||
|
||||
newTokenExternalUrlEvent.parameters.push(
|
||||
new ethereum.EventParam('token', ethereum.Value.fromUnsignedBigInt(token))
|
||||
);
|
||||
newTokenExternalUrlEvent.parameters.push(
|
||||
new ethereum.EventParam(
|
||||
'externalURL',
|
||||
ethereum.Value.fromString(externalURL)
|
||||
)
|
||||
);
|
||||
newTokenExternalUrlEvent.parameters.push(
|
||||
new ethereum.EventParam(
|
||||
'triggeredBy',
|
||||
ethereum.Value.fromAddress(triggeredBy)
|
||||
)
|
||||
);
|
||||
|
||||
newTokenExternalUrlEvent.transaction.hash = Bytes.fromI32(event_count);
|
||||
newTokenExternalUrlEvent.logIndex = new BigInt(event_count);
|
||||
|
||||
return newTokenExternalUrlEvent;
|
||||
}
|
||||
|
||||
export function createNewTokenImageEvent(
|
||||
event_count: i32,
|
||||
token: BigInt,
|
||||
image: string,
|
||||
triggeredBy: Address
|
||||
): NewTokenImageEvent {
|
||||
let newTokenImageEvent = changetype<NewTokenImageEvent>(newMockEvent());
|
||||
|
||||
newTokenImageEvent.parameters = new Array();
|
||||
|
||||
newTokenImageEvent.parameters.push(
|
||||
new ethereum.EventParam('token', ethereum.Value.fromUnsignedBigInt(token))
|
||||
);
|
||||
newTokenImageEvent.parameters.push(
|
||||
new ethereum.EventParam('image', ethereum.Value.fromString(image))
|
||||
);
|
||||
newTokenImageEvent.parameters.push(
|
||||
new ethereum.EventParam(
|
||||
'triggeredBy',
|
||||
ethereum.Value.fromAddress(triggeredBy)
|
||||
)
|
||||
);
|
||||
|
||||
newTokenImageEvent.transaction.hash = Bytes.fromI32(event_count);
|
||||
newTokenImageEvent.logIndex = new BigInt(event_count);
|
||||
|
||||
return newTokenImageEvent;
|
||||
}
|
||||
|
||||
export function createNewTokenNameEvent(
|
||||
event_count: i32,
|
||||
token: BigInt,
|
||||
name: string,
|
||||
triggeredBy: Address
|
||||
): NewTokenNameEvent {
|
||||
let newTokenNameEvent = changetype<NewTokenNameEvent>(newMockEvent());
|
||||
|
||||
newTokenNameEvent.parameters = new Array();
|
||||
|
||||
newTokenNameEvent.parameters.push(
|
||||
new ethereum.EventParam('token', ethereum.Value.fromUnsignedBigInt(token))
|
||||
);
|
||||
newTokenNameEvent.parameters.push(
|
||||
new ethereum.EventParam('name', ethereum.Value.fromString(name))
|
||||
);
|
||||
newTokenNameEvent.parameters.push(
|
||||
new ethereum.EventParam(
|
||||
'triggeredBy',
|
||||
ethereum.Value.fromAddress(triggeredBy)
|
||||
)
|
||||
);
|
||||
|
||||
newTokenNameEvent.transaction.hash = Bytes.fromI32(event_count);
|
||||
newTokenNameEvent.logIndex = new BigInt(event_count);
|
||||
|
||||
return newTokenNameEvent;
|
||||
}
|
||||
|
||||
export function createTokenRoleGrantedEvent(
|
||||
event_count: i32,
|
||||
tokenId: BigInt,
|
||||
role: i32,
|
||||
toAddress: Address,
|
||||
byAddress: Address
|
||||
): TokenRoleGrantedEvent {
|
||||
let tokenRoleGrantedEvent = changetype<TokenRoleGrantedEvent>(newMockEvent());
|
||||
|
||||
tokenRoleGrantedEvent.parameters = new Array();
|
||||
|
||||
tokenRoleGrantedEvent.parameters.push(
|
||||
new ethereum.EventParam(
|
||||
'tokenId',
|
||||
ethereum.Value.fromUnsignedBigInt(tokenId)
|
||||
)
|
||||
);
|
||||
tokenRoleGrantedEvent.parameters.push(
|
||||
new ethereum.EventParam(
|
||||
'role',
|
||||
ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(role))
|
||||
)
|
||||
);
|
||||
tokenRoleGrantedEvent.parameters.push(
|
||||
new ethereum.EventParam('toAddress', ethereum.Value.fromAddress(toAddress))
|
||||
);
|
||||
tokenRoleGrantedEvent.parameters.push(
|
||||
new ethereum.EventParam('byAddress', ethereum.Value.fromAddress(byAddress))
|
||||
);
|
||||
|
||||
tokenRoleGrantedEvent.transaction.hash = Bytes.fromI32(event_count);
|
||||
tokenRoleGrantedEvent.logIndex = new BigInt(event_count);
|
||||
|
||||
return tokenRoleGrantedEvent;
|
||||
}
|
||||
|
||||
export function createTokenRoleRevokedEvent(
|
||||
event_count: i32,
|
||||
tokenId: BigInt,
|
||||
role: i32,
|
||||
toAddress: Address,
|
||||
byAddress: Address
|
||||
): TokenRoleRevokedEvent {
|
||||
let tokenRoleRevokedEvent = changetype<TokenRoleRevokedEvent>(newMockEvent());
|
||||
|
||||
tokenRoleRevokedEvent.parameters = new Array();
|
||||
|
||||
tokenRoleRevokedEvent.parameters.push(
|
||||
new ethereum.EventParam(
|
||||
'tokenId',
|
||||
ethereum.Value.fromUnsignedBigInt(tokenId)
|
||||
)
|
||||
);
|
||||
tokenRoleRevokedEvent.parameters.push(
|
||||
new ethereum.EventParam(
|
||||
'role',
|
||||
ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(role))
|
||||
)
|
||||
);
|
||||
tokenRoleRevokedEvent.parameters.push(
|
||||
new ethereum.EventParam('toAddress', ethereum.Value.fromAddress(toAddress))
|
||||
);
|
||||
tokenRoleRevokedEvent.parameters.push(
|
||||
new ethereum.EventParam('byAddress', ethereum.Value.fromAddress(byAddress))
|
||||
);
|
||||
|
||||
tokenRoleRevokedEvent.transaction.hash = Bytes.fromI32(event_count);
|
||||
tokenRoleRevokedEvent.logIndex = new BigInt(event_count);
|
||||
|
||||
return tokenRoleRevokedEvent;
|
||||
}
|
||||
|
||||
export function createTransferEvent(
|
||||
event_count: i32,
|
||||
from: Address,
|
||||
to: Address,
|
||||
tokenId: BigInt
|
||||
): TransferEvent {
|
||||
let transferEvent = changetype<TransferEvent>(newMockEvent());
|
||||
|
||||
transferEvent.parameters = new Array();
|
||||
|
||||
transferEvent.parameters.push(
|
||||
new ethereum.EventParam('from', ethereum.Value.fromAddress(from))
|
||||
);
|
||||
transferEvent.parameters.push(
|
||||
new ethereum.EventParam('to', ethereum.Value.fromAddress(to))
|
||||
);
|
||||
transferEvent.parameters.push(
|
||||
new ethereum.EventParam(
|
||||
'tokenId',
|
||||
ethereum.Value.fromUnsignedBigInt(tokenId)
|
||||
)
|
||||
);
|
||||
|
||||
transferEvent.transaction.hash = Bytes.fromI32(event_count);
|
||||
transferEvent.logIndex = new BigInt(event_count);
|
||||
|
||||
return transferEvent;
|
||||
}
|
||||
|
||||
export const CONTRACT: Address = Address.fromString(
|
||||
'0x0000000000000000000000000000000000000000'
|
||||
);
|
||||
export const CONTRACT_OWNER: Address = Address.fromString(
|
||||
'0x1000000000000000000000000000000000000001'
|
||||
);
|
||||
export const TOKEN_OWNER_ONE: Address = Address.fromString(
|
||||
'0x2000000000000000000000000000000000000002'
|
||||
);
|
||||
export const TOKEN_OWNER_TWO: Address = Address.fromString(
|
||||
'0x3000000000000000000000000000000000000003'
|
||||
);
|
||||
|
||||
export function handleTransfers(events: TransferEvent[]): void {
|
||||
events.forEach((event) => {
|
||||
handleTransfer(event);
|
||||
});
|
||||
}
|
||||
|
||||
export function handleNewTokenNames(events: NewTokenNameEvent[]): void {
|
||||
events.forEach((event) => {
|
||||
handleNewTokenName(event);
|
||||
});
|
||||
}
|
||||
|
||||
export function handleNewTokenDescriptions(
|
||||
events: NewTokenDescriptionEvent[]
|
||||
): void {
|
||||
events.forEach((event) => {
|
||||
handleNewTokenDescription(event);
|
||||
});
|
||||
}
|
||||
|
||||
export function handleNewTokenENSAddresses(events: NewTokenENSEvent[]): void {
|
||||
events.forEach((event) => {
|
||||
handleNewTokenENS(event);
|
||||
});
|
||||
}
|
||||
|
||||
export function handleNewTokenExternalURLs(
|
||||
events: NewTokenExternalURLEvent[]
|
||||
): void {
|
||||
events.forEach((event) => {
|
||||
handleNewTokenExternalURL(event);
|
||||
});
|
||||
}
|
||||
|
||||
export function handleNewBuilds(events: NewBuildEvent[]): void {
|
||||
events.forEach((event) => {
|
||||
handleNewBuild(event);
|
||||
});
|
||||
}
|
||||
|
||||
export function handleNewTokenLogos(events: NewTokenLogoEvent[]): void {
|
||||
events.forEach((event) => {
|
||||
handleNewTokenLogo(event);
|
||||
});
|
||||
}
|
||||
|
||||
export function handleApprovals(events: ApprovalEvent[]): void {
|
||||
events.forEach((event) => {
|
||||
handleApproval(event);
|
||||
});
|
||||
}
|
||||
|
||||
export function handleApprovalForAlls(events: ApprovalForAllEvent[]): void {
|
||||
events.forEach((event) => {
|
||||
handleApprovalForAll(event);
|
||||
});
|
||||
}
|
||||
|
||||
export function handleCollectionRoleGranteds(
|
||||
events: CollectionRoleGrantedEvent[]
|
||||
): void {
|
||||
events.forEach((event) => {
|
||||
handleCollectionRoleGranted(event);
|
||||
});
|
||||
}
|
||||
|
||||
export function handleCollectionRoleRevokeds(
|
||||
events: CollectionRoleRevokedEvent[]
|
||||
): void {
|
||||
events.forEach((event) => {
|
||||
handleCollectionRoleRevoked(event);
|
||||
});
|
||||
}
|
||||
|
||||
export function handleTokenRoleGranteds(events: TokenRoleGrantedEvent[]): void {
|
||||
events.forEach((event) => {
|
||||
handleTokenRoleGranted(event);
|
||||
});
|
||||
}
|
||||
|
||||
export function handleTokenRoleRevokeds(events: TokenRoleRevokedEvent[]): void {
|
||||
events.forEach((event) => {
|
||||
handleTokenRoleRevoked(event);
|
||||
});
|
||||
}
|
||||
|
||||
export function makeEventId(id: i32): string {
|
||||
return Bytes.fromI32(id).toHexString() + '00000000';
|
||||
}
|
||||
Loading…
Reference in New Issue