diff --git a/packages/subgraph/tests/dao/dao_v1_0_0.test.ts b/packages/subgraph/tests/dao/dao_v1_0_0.test.ts index 5c3aab97b..17abdba13 100644 --- a/packages/subgraph/tests/dao/dao_v1_0_0.test.ts +++ b/packages/subgraph/tests/dao/dao_v1_0_0.test.ts @@ -61,6 +61,17 @@ import { TransactionActionsProposal } from '../../generated/schema'; import {Executed} from '../../generated/templates/DaoTemplateV1_0_0/DAO'; +import { + ExtendedDao, + ExtendedERC20Balance, + ExtendedERC20Contract, + ExtendedERC20Transfer, + ExtendedERC721Balance, + ExtendedERC721Contract, + ExtendedERC721Transfer, + ExtendedNativeBalance, + ExtendedNativeTransfer +} from '../helpers/extended-schema'; const eq = assert.fieldEquals; @@ -68,6 +79,9 @@ let daoId = Address.fromString(DAO_ADDRESS).toHexString(); let tokenId = Address.fromString(DAO_TOKEN_ADDRESS).toHexString(); let balanceId = daoId.concat('_').concat(tokenId); +let daoTokenContract: ExtendedERC20Contract; +let erc721Contract: ExtendedERC721Contract; + // create Executed event with multiple actions function createExecutedEvent( tuple: ethereum.Value[][], @@ -113,66 +127,66 @@ function createExecutedEvent( } test('Run dao (handleMetadataSet) mappings with mock event', () => { - // create state - let entityID = Address.fromString(DAO_ADDRESS).toHexString(); - createDaoEntityState(entityID, ADDRESS_ONE, DAO_TOKEN_ADDRESS); + // Create state + let dao = new ExtendedDao().withDefaultValues(); + dao.buildOrUpdate(); - let metadata = 'new-metadata'; + let newMetadata = 'new-metadata'; - // handle event - _handleMetadataSet(entityID, metadata); + // Handle event + _handleMetadataSet(dao.id, newMetadata); - // checks - assert.fieldEquals('Dao', entityID, 'id', entityID); - assert.fieldEquals('Dao', entityID, 'metadata', metadata); + // Checks + // Expected changes + dao.metadata = newMetadata; + + // Assert dao entity + dao.assertEntity(); clearStore(); }); describe('handleNativeTokenDeposited', () => { test('create entities with correct values', () => { + let dao = new ExtendedDao().withDefaultValues(); + // create event - let newEvent = createNewNativeTokenDepositedEvent( - ADDRESS_ONE, - ONE_ETH, - DAO_ADDRESS - ); + let newEvent = dao.createEvent_NativeTokenDeposited(ADDRESS_ONE, ONE_ETH); + + // handle event + handleNativeTokenDeposited(newEvent); + + // check NativeBalance entity + let nativeBalance = new ExtendedNativeBalance().withDefaultValues(); + // expected changes + let balance = BigInt.fromString(ONE_ETH); + nativeBalance.balance = balance; + nativeBalance.lastUpdated = newEvent.block.timestamp; + // assert + nativeBalance.assertEntity(); + + // check NativeTransfer entity let txHash = newEvent.transaction.hash; let logIndex = newEvent.transactionLogIndex; - let timestamp = newEvent.block.timestamp; let transferId = getTransferId(txHash, logIndex, 0); - let balanceId = daoId.concat('_').concat(ADDRESS_ZERO); - - // handle event - handleNativeTokenDeposited(newEvent); + let nativeTransfer = new ExtendedNativeTransfer().withDefaultValues( + transferId + ); + // expected changes + nativeTransfer.amount = balance; + nativeTransfer.txHash = txHash; - // check NativeBalance entity - eq('NativeBalance', balanceId, 'id', balanceId); - eq('NativeBalance', balanceId, 'dao', daoId); - eq('NativeBalance', balanceId, 'balance', ONE_ETH); - eq('NativeBalance', balanceId, 'lastUpdated', timestamp.toString()); - - eq('NativeTransfer', transferId, 'id', transferId); - eq('NativeTransfer', transferId, 'dao', daoId); - eq('NativeTransfer', transferId, 'from', ADDRESS_ONE); - eq('NativeTransfer', transferId, 'to', DAO_ADDRESS); - eq('NativeTransfer', transferId, 'amount', ONE_ETH); - eq('NativeTransfer', transferId, 'type', 'Deposit'); - eq('NativeTransfer', transferId, 'reference', 'Native Deposit'); - eq('NativeTransfer', transferId, 'txHash', txHash.toHexString()); - eq('NativeTransfer', transferId, 'createdAt', timestamp.toString()); + nativeTransfer.assertEntity(); clearStore(); }); test('correctly handles multiple events and updates balance', () => { + let dao = new ExtendedDao().withDefaultValues(); + // create event - let newEvent = createNewNativeTokenDepositedEvent( - ADDRESS_ONE, - ONE_ETH, - DAO_ADDRESS - ); + let newEvent = dao.createEvent_NativeTokenDeposited(ADDRESS_ONE, ONE_ETH); newEvent.transactionLogIndex = BigInt.fromI32(2); handleNativeTokenDeposited(newEvent); @@ -180,14 +194,19 @@ describe('handleNativeTokenDeposited', () => { newEvent.transactionLogIndex = BigInt.fromI32(3); handleNativeTokenDeposited(newEvent); - let balanceId = daoId.concat('_').concat(ADDRESS_ZERO); - - let eachAmount = BigInt.fromString(ONE_ETH); - let finalAmount = eachAmount.plus(eachAmount).toString(); - assert.entityCount('NativeTransfer', 2); assert.entityCount('NativeBalance', 1); - eq('NativeBalance', balanceId, 'balance', finalAmount); + + // check NativeBalance entity + let nativeBalance = new ExtendedNativeBalance().withDefaultValues(); + + // expected changes + let eachAmount = BigInt.fromString(ONE_ETH); + let finalAmount = eachAmount.plus(eachAmount); + nativeBalance.balance = finalAmount; + nativeBalance.lastUpdated = newEvent.block.timestamp; + // assert + nativeBalance.assertEntity(); clearStore(); }); @@ -195,9 +214,11 @@ describe('handleNativeTokenDeposited', () => { describe('handleDeposited: ', () => { beforeAll(() => { - createTokenCalls(DAO_TOKEN_ADDRESS, 'DAO Token', 'DAOT', '6', '10'); - getBalanceOf(DAO_TOKEN_ADDRESS, DAO_ADDRESS, ERC20_AMOUNT_HALF); - getBalanceOf(DAO_TOKEN_ADDRESS, DAO_TOKEN_ADDRESS, ERC20_AMOUNT_HALF); + daoTokenContract = new ExtendedERC20Contract().withDefaultValues(); + let totalSupply = '10'; + daoTokenContract.mockCall_createTokenCalls(totalSupply); + daoTokenContract.mockCall_balanceOf(DAO_ADDRESS, ERC20_AMOUNT_HALF); + daoTokenContract.mockCall_balanceOf(DAO_TOKEN_ADDRESS, ERC20_AMOUNT_HALF); }); afterEach(() => { @@ -205,12 +226,12 @@ describe('handleDeposited: ', () => { }); test('ERC20: creates entities with correct values', () => { - let newEvent = createNewDepositedEvent( + let dao = new ExtendedDao().withDefaultValues(); + + let newEvent = dao.createEvent_Deposited( ADDRESS_ONE, - DAO_TOKEN_ADDRESS, ERC20_AMOUNT_HALF, - STRING_DATA, - DAO_ADDRESS + STRING_DATA ); let txHash = newEvent.transaction.hash; @@ -222,123 +243,134 @@ describe('handleDeposited: ', () => { let transferId = getTransferId(txHash, logIndex, 0); // check ERC20Contract entity - eq('ERC20Contract', tokenId, 'id', tokenId); - eq('ERC20Contract', tokenId, 'name', 'DAO Token'); - eq('ERC20Contract', tokenId, 'symbol', 'DAOT'); - eq('ERC20Contract', tokenId, 'decimals', '6'); + daoTokenContract.assertEntity(); assert.entityCount('ERC20Contract', 1); // check ERC20Balance entity - eq('ERC20Balance', balanceId, 'id', balanceId); - eq('ERC20Balance', balanceId, 'token', tokenId); - eq('ERC20Balance', balanceId, 'dao', daoId); - eq('ERC20Balance', balanceId, 'balance', ERC20_AMOUNT_HALF); - eq('ERC20Balance', balanceId, 'lastUpdated', timestamp.toString()); + let erc20Balance = new ExtendedERC20Balance().withDefaultValues(); + // expected changes + let balance = BigInt.fromString(ERC20_AMOUNT_HALF); + erc20Balance.balance = balance; + erc20Balance.lastUpdated = timestamp; + // assert + erc20Balance.assertEntity(); assert.entityCount('ERC20Contract', 1); // Check ERC20Transfer - let from = newEvent.params.sender.toHexString(); - eq('ERC20Transfer', transferId, 'id', transferId); - eq('ERC20Transfer', transferId, 'dao', daoId); - eq('ERC20Transfer', transferId, 'token', tokenId); - eq('ERC20Transfer', transferId, 'amount', ERC20_AMOUNT_HALF); - eq('ERC20Transfer', transferId, 'from', from); - eq('ERC20Transfer', transferId, 'to', DAO_ADDRESS); - eq('ERC20Transfer', transferId, 'type', 'Deposit'); - eq('ERC20Transfer', transferId, 'txHash', txHash.toHexString()); - eq('ERC20Transfer', transferId, 'createdAt', timestamp.toString()); + let erc20Transfer = new ExtendedERC20Transfer().withDefaultValue( + transferId + ); + // expected changes + erc20Transfer.amount = balance; + erc20Transfer.txHash = txHash; + // assert + erc20Transfer.assertEntity(true); assert.entityCount('ERC20Transfer', 1); }); test('ERC20: creates multiple events and updates balance', () => { - let newEvent = createNewDepositedEvent( + let dao = new ExtendedDao().withDefaultValues(); + + let newEvent = dao.createEvent_Deposited( ADDRESS_ONE, - DAO_TOKEN_ADDRESS, ERC20_AMOUNT_HALF, - STRING_DATA, - DAO_ADDRESS + STRING_DATA ); handleDeposited(newEvent); - eq('ERC20Balance', balanceId, 'balance', ERC20_AMOUNT_HALF); - getBalanceOf(DAO_TOKEN_ADDRESS, DAO_ADDRESS, ERC20_AMOUNT_FULL); + // check ERC20Balance entity + let erc20Balance = new ExtendedERC20Balance().withDefaultValues(); + // expected changes + let balance = BigInt.fromString(ERC20_AMOUNT_HALF); + erc20Balance.balance = balance; + erc20Balance.lastUpdated = newEvent.block.timestamp; + // assert + erc20Balance.assertEntity(); + + daoTokenContract.mockCall_balanceOf(DAO_ADDRESS, ERC20_AMOUNT_FULL); newEvent.transactionLogIndex = BigInt.fromI32(2); handleDeposited(newEvent); - eq('ERC20Balance', balanceId, 'balance', ERC20_AMOUNT_FULL); + // check ERC20Balance entity for updated balance + // expected changes + let balance2 = BigInt.fromString(ERC20_AMOUNT_FULL); + erc20Balance.balance = balance2; + // assert + erc20Balance.assertEntity(); assert.entityCount('ERC20Transfer', 2); }); test('ETH: creates entities with correct values', () => { let token = ADDRESS_ZERO; - let newEvent = createNewDepositedEvent( - ADDRESS_ONE, - token, - ONE_ETH, - STRING_DATA, - DAO_ADDRESS - ); + let dao = new ExtendedDao().withDefaultValues(); + dao.token = token; + + let newEvent = dao.createEvent_Deposited(ADDRESS_ONE, ONE_ETH, STRING_DATA); let txHash = newEvent.transaction.hash; let logIndex = newEvent.transactionLogIndex; - let timestamp = newEvent.block.timestamp; - let from = newEvent.params.sender.toHexString(); handleDeposited(newEvent); - let tokenId = Address.fromString(token).toHexString(); - let balanceId = daoId.concat('_').concat(tokenId); - let transferId = getTransferId(txHash, logIndex, 0); - // check NativeBalance entity - eq('NativeBalance', balanceId, 'id', balanceId); - eq('NativeBalance', balanceId, 'dao', daoId); - eq('NativeBalance', balanceId, 'balance', ONE_ETH); - eq('NativeBalance', balanceId, 'lastUpdated', timestamp.toString()); + let nativeBalance = new ExtendedNativeBalance().withDefaultValues(); + + // expected changes + let balance = BigInt.fromString(ONE_ETH); + nativeBalance.balance = balance; + nativeBalance.lastUpdated = newEvent.block.timestamp; + // assert + nativeBalance.assertEntity(); // Check NativeTransfer - eq('NativeTransfer', transferId, 'id', transferId); - eq('NativeTransfer', transferId, 'dao', daoId); - eq('NativeTransfer', transferId, 'amount', ONE_ETH); - eq('NativeTransfer', transferId, 'from', from); - eq('NativeTransfer', transferId, 'to', DAO_ADDRESS); - eq('NativeTransfer', transferId, 'type', 'Deposit'); - eq('NativeTransfer', transferId, 'txHash', txHash.toHexString()); - eq('NativeTransfer', transferId, 'createdAt', timestamp.toString()); + let transferId = getTransferId(txHash, logIndex, 0); + let nativeTransfer = new ExtendedNativeTransfer().withDefaultValues( + transferId + ); + // expected changes + nativeTransfer.amount = balance; + nativeTransfer.txHash = txHash; + nativeTransfer.reference = STRING_DATA; + + nativeTransfer.assertEntity(); }); test('ETH: correctly handles multiple events and updates balance', () => { // create event let token = ADDRESS_ZERO; - let newEvent = createNewDepositedEvent( - ADDRESS_ONE, - token, - ONE_ETH, - STRING_DATA, - DAO_ADDRESS - ); + + let dao = new ExtendedDao().withDefaultValues(); + dao.token = token; + + let newEvent = dao.createEvent_Deposited(ADDRESS_ONE, ONE_ETH, STRING_DATA); handleDeposited(newEvent); newEvent.transactionLogIndex = BigInt.fromI32(2); handleDeposited(newEvent); - let balanceId = daoId.concat('_').concat(ADDRESS_ZERO); - let eachAmount = BigInt.fromString(ONE_ETH); - let finalAmount = eachAmount.plus(eachAmount).toString(); + let finalAmount = eachAmount.plus(eachAmount); + + // check NativeBalance entity + let nativeBalance = new ExtendedNativeBalance().withDefaultValues(); + // expected changes + nativeBalance.balance = finalAmount; + nativeBalance.lastUpdated = newEvent.block.timestamp; + // assert + nativeBalance.assertEntity(); assert.entityCount('NativeTransfer', 2); assert.entityCount('NativeBalance', 1); - eq('NativeBalance', balanceId, 'balance', finalAmount); }); }); describe('handleCallbackReceived: ', () => { beforeAll(() => { - createTokenCalls(DAO_TOKEN_ADDRESS, 'name', 'symbol', null, null); + erc721Contract = new ExtendedERC721Contract().withDefaultValues(); + erc721Contract.mockCall_createTokenCalls(); getSupportsInterface(DAO_TOKEN_ADDRESS, '0x01ffc9a7', true); getSupportsInterface(DAO_TOKEN_ADDRESS, '80ac58cd', true); @@ -347,10 +379,11 @@ describe('handleCallbackReceived: ', () => { describe('ERC721 Received: ', () => { test('create entities with correct values', () => { + let tokenId = BigInt.fromU32(1); let tupleArray: Array = [ ethereum.Value.fromAddress(Address.fromString(ADDRESS_THREE)), ethereum.Value.fromAddress(Address.fromString(ADDRESS_FOUR)), - ethereum.Value.fromUnsignedBigInt(BigInt.fromU32(1)), + ethereum.Value.fromUnsignedBigInt(tokenId), ethereum.Value.fromBytes(Bytes.fromHexString('0x')) ]; @@ -360,10 +393,10 @@ describe('handleCallbackReceived: ', () => { true ); - let newEvent = createCallbackReceivedEvent( - DAO_ADDRESS, - Bytes.fromHexString(onERC721Received), - DAO_TOKEN_ADDRESS, + let dao = new ExtendedDao().withDefaultValues(); + + let newEvent = dao.createEvent_CallbackReceived( + onERC721Received, functionData ); @@ -376,28 +409,28 @@ describe('handleCallbackReceived: ', () => { let transferId = getTransferId(txHash, logIndex, 0); // check ERC721Contract entity - eq('ERC721Contract', tokenId, 'id', tokenId); - eq('ERC721Contract', tokenId, 'name', 'name'); - eq('ERC721Contract', tokenId, 'symbol', 'symbol'); + erc721Contract.assertEntity(); assert.entityCount('ERC721Contract', 1); // check ERC721Balance entity - eq('ERC721Balance', balanceId, 'id', balanceId); - eq('ERC721Balance', balanceId, 'token', tokenId); - eq('ERC721Balance', balanceId, 'dao', daoId); - eq('ERC721Balance', balanceId, 'tokenIds', '[1]'); - eq('ERC721Balance', balanceId, 'lastUpdated', timestamp.toString()); + let erc721Balance = new ExtendedERC721Balance().withDefaultValues(); + // expexted changes + erc721Balance.tokenIds = [tokenId]; + erc721Balance.lastUpdated = timestamp; + erc721Balance.assertEntity(); assert.entityCount('ERC721Balance', 1); // Check ERC721Transfer - eq('ERC721Transfer', transferId, 'id', transferId); - eq('ERC721Transfer', transferId, 'dao', daoId); - eq('ERC721Transfer', transferId, 'tokenId', '1'); - eq('ERC721Transfer', transferId, 'from', ADDRESS_FOUR); - eq('ERC721Transfer', transferId, 'to', DAO_ADDRESS); - eq('ERC721Transfer', transferId, 'type', 'Deposit'); - eq('ERC721Transfer', transferId, 'txHash', txHash.toHexString()); - eq('ERC721Transfer', transferId, 'createdAt', timestamp.toString()); + let erc721Transfer = new ExtendedERC721Transfer().withDefaultValues( + transferId + ); + // expected changes + erc721Transfer.from = Address.fromHexString(ADDRESS_FOUR); + erc721Transfer.tokenId = tokenId; + erc721Transfer.txHash = txHash; + erc721Transfer.createdAt = timestamp; + // assert + erc721Transfer.assertEntity(); clearStore(); }); @@ -416,10 +449,10 @@ describe('handleCallbackReceived: ', () => { true ); - let newEvent = createCallbackReceivedEvent( - DAO_ADDRESS, - Bytes.fromHexString(onERC721Received), - DAO_TOKEN_ADDRESS, + let dao = new ExtendedDao().withDefaultValues(); + + let newEvent = dao.createEvent_CallbackReceived( + onERC721Received, functionData ); @@ -431,10 +464,8 @@ describe('handleCallbackReceived: ', () => { onERC721Received, true ); - newEvent = createCallbackReceivedEvent( - DAO_ADDRESS, - Bytes.fromHexString(onERC721Received), - DAO_TOKEN_ADDRESS, + newEvent = dao.createEvent_CallbackReceived( + onERC721Received, functionData ); @@ -442,7 +473,12 @@ describe('handleCallbackReceived: ', () => { assert.entityCount('ERC721Contract', 1); assert.entityCount('ERC721Transfer', 1); assert.entityCount('ERC721Balance', 1); - eq('ERC721Balance', balanceId, 'tokenIds', '[1]'); + // check ERC721Balance entity + let erc721Balance = new ExtendedERC721Balance().withDefaultValues(); + // expexted changes + erc721Balance.tokenIds = [BigInt.fromU32(1)]; + erc721Balance.lastUpdated = newEvent.block.timestamp; + erc721Balance.assertEntity(); // Change log index so it will enforce to generate new transferId // to make sure we can assert ERC721Transfer to be 2. @@ -454,7 +490,10 @@ describe('handleCallbackReceived: ', () => { assert.entityCount('ERC721Contract', 1); assert.entityCount('ERC721Transfer', 2); assert.entityCount('ERC721Balance', 1); - eq('ERC721Balance', balanceId, 'tokenIds', '[1, 2]'); + // check ERC721Balance entity + // expexted changes + erc721Balance.tokenIds = [BigInt.fromU32(1), BigInt.fromU32(2)]; + erc721Balance.assertEntity(); }); }); }); diff --git a/packages/subgraph/tests/helpers/method-classes.ts b/packages/subgraph/tests/helpers/method-classes.ts index b5b610261..6b34d1d8d 100644 --- a/packages/subgraph/tests/helpers/method-classes.ts +++ b/packages/subgraph/tests/helpers/method-classes.ts @@ -3,15 +3,27 @@ * The classes of this file are meant to be incorporated into the classes of ./extended-schema.ts */ -import {Address, bigInt, BigInt, ethereum} from '@graphprotocol/graph-ts'; -import {log} from 'matchstick-as'; +import {Address, BigInt, Bytes, ethereum} from '@graphprotocol/graph-ts'; import { + Dao, + ERC20Balance, ERC20Contract, + ERC20Transfer, + ERC721Balance, + ERC721Contract, + ERC721Transfer, + NativeBalance, + NativeTransfer, TokenVotingPlugin, TokenVotingProposal, TokenVotingVote, TokenVotingVoter } from '../../generated/schema'; +import { + CallbackReceived, + Deposited, + NativeTokenDeposited +} from '../../generated/templates/DaoTemplateV1_0_0/DAO'; import { ProposalCreated, ProposalExecuted, @@ -24,6 +36,7 @@ import { VOTING_MODES, VOTING_MODE_INDEXES } from '../../src/utils/constants'; +import {getTransferId} from '../../src/utils/tokens/common'; import { ADDRESS_ONE, ALLOW_FAILURE_MAP, @@ -45,8 +58,17 @@ import { MIN_DURATION, ONE, DAO_TOKEN_ADDRESS, - STRING_DATA + STRING_DATA, + ADDRESS_TWO, + ADDRESS_THREE, + ADDRESS_ZERO } from '../constants'; +import { + createCallbackReceivedEvent, + createNewDepositedEvent, + createNewNativeTokenDepositedEvent, + getBalanceOf +} from '../dao/utils'; import { createNewProposalCreatedEvent, createNewProposalExecutedEvent, @@ -54,18 +76,246 @@ import { createNewVotingSettingsUpdatedEvent, getProposalCountCall } from '../token/utils'; -import {createGetProposalCall, createTotalVotingPowerCall} from '../utils'; +import { + createGetProposalCall, + createTotalVotingPowerCall, + createTokenCalls +} from '../utils'; + +// ERC721Contract +class ERC721ContractMethods extends ERC721Contract { + withDefaultValues(): ERC721ContractMethods { + this.id = Address.fromHexString(DAO_TOKEN_ADDRESS).toHexString(); + this.name = 'name'; + this.symbol = 'symbol'; + return this; + } + + // calls + mockCall_createTokenCalls(): void { + if (!this.name) { + throw new Error('Name is null'); + } + if (!this.symbol) { + throw new Error('Symbol is null'); + } + // we cast to string only for stoping rust compiler complaints. + createTokenCalls( + this.id, + this.name as string, + this.symbol as string, + null, + null + ); + } +} + +// ERC721Balance +class ERC721BalanceMethods extends ERC721Balance { + withDefaultValues(): ERC721BalanceMethods { + let daoId = Address.fromString(DAO_ADDRESS).toHexString(); + let tokenId = Address.fromString(DAO_TOKEN_ADDRESS).toHexString(); + let balanceId = daoId.concat('_').concat(tokenId); + + this.id = balanceId; + this.token = Address.fromHexString(DAO_TOKEN_ADDRESS).toHexString(); + this.dao = DAO_ADDRESS; + this.tokenIds = [BigInt.zero()]; + this.lastUpdated = BigInt.zero(); + return this; + } +} + +// ERC721Transfer +class ERC721TransferMethods extends ERC721Transfer { + withDefaultValues( + id: string = getTransferId(Bytes.empty(), BigInt.zero(), 0) + ): ERC721TransferMethods { + this.id = id; + this.dao = DAO_ADDRESS; + this.token = Address.fromString(DAO_TOKEN_ADDRESS).toHexString(); + this.tokenId = BigInt.zero(); + this.from = Address.fromHexString(ADDRESS_ONE); + this.to = Address.fromHexString(DAO_ADDRESS); + this.proposal = PROPOSAL_ENTITY_ID; + this.type = 'Deposit'; + this.txHash = Bytes.empty(); + this.createdAt = BigInt.fromString(CREATED_AT); + return this; + } +} +// ERC20Contract class ERC20ContractMethods extends ERC20Contract { withDefaultValues(): ERC20ContractMethods { - this.id = Address.fromHexString(CONTRACT_ADDRESS).toHexString(); - this.name = 'Test Token'; - this.symbol = 'TT'; - this.decimals = 18; + this.id = Address.fromHexString(DAO_TOKEN_ADDRESS).toHexString(); + this.name = 'DAO Token'; + this.symbol = 'DAOT'; + this.decimals = 6; return this; } + + // calls + mockCall_createTokenCalls(totalSupply: string | null = null): void { + if (!this.name) { + throw new Error('Name is null'); + } + if (!this.symbol) { + throw new Error('Symbol is null'); + } + // we cast to string only for stoping rust compiler complaints. + createTokenCalls( + this.id, + this.name as string, + this.symbol as string, + this.decimals.toString(), + totalSupply + ); + } + + mockCall_balanceOf(account: string, amount: string): void { + getBalanceOf(this.id, account, amount); + } } + +// ERC20Balance +class ERC20BalanceMethods extends ERC20Balance { + withDefaultValues(): ERC20BalanceMethods { + let daoId = Address.fromString(DAO_ADDRESS).toHexString(); + let tokenId = Address.fromString(DAO_TOKEN_ADDRESS).toHexString(); + let balanceId = daoId.concat('_').concat(tokenId); + + this.id = balanceId; + this.token = Address.fromHexString(DAO_TOKEN_ADDRESS).toHexString(); + this.dao = DAO_ADDRESS; + this.balance = BigInt.zero(); + this.lastUpdated = BigInt.zero(); + return this; + } +} + +class ERC20TransferMethods extends ERC20Transfer { + withDefaultValue( + id: string = getTransferId(Bytes.empty(), BigInt.zero(), 0) + ): ERC20TransferMethods { + this.id = id; + this.dao = DAO_ADDRESS; + this.token = Address.fromString(DAO_TOKEN_ADDRESS).toHexString(); + this.amount = BigInt.zero(); + this.from = Address.fromHexString(ADDRESS_ONE); + this.to = Address.fromHexString(DAO_ADDRESS); + this.proposal = PROPOSAL_ENTITY_ID; + this.type = 'Deposit'; + this.txHash = Bytes.empty(); + this.createdAt = BigInt.fromString(CREATED_AT); + + return this; + } +} + +// NativeTransfer +class NativeTransferMethods extends NativeTransfer { + withDefaultValues( + id: string = getTransferId(Bytes.empty(), BigInt.zero(), 0) + ): NativeTransferMethods { + this.id = id; + this.dao = DAO_ADDRESS; + this.amount = BigInt.zero(); + this.from = Address.fromHexString(ADDRESS_ONE); + this.to = Address.fromHexString(DAO_ADDRESS); + this.reference = 'Native Deposit'; + this.proposal = PROPOSAL_ENTITY_ID; + this.type = 'Deposit'; + this.txHash = Bytes.empty(); + this.createdAt = BigInt.fromString(CREATED_AT); + + return this; + } +} + +// NativeBalance +class NativeBalanceMethods extends NativeBalance { + withDefaultValues(): NativeBalanceMethods { + this.id = DAO_ADDRESS.concat('_').concat(ADDRESS_ZERO); + this.dao = DAO_ADDRESS; + this.balance = BigInt.zero(); + this.lastUpdated = BigInt.zero(); + + return this; + } +} + +// DAO +class DaoMethods extends Dao { + withDefaultValues(): DaoMethods { + this.id = DAO_ADDRESS; + this.subdomain = ''; + this.creator = Address.fromHexString(ADDRESS_ONE); + this.metadata = STRING_DATA; + this.createdAt = BigInt.fromString(CREATED_AT); + this.token = Address.fromString(DAO_TOKEN_ADDRESS).toHexString(); + this.trustedForwarder = Address.fromHexString(ADDRESS_TWO); + this.signatureValidator = Address.fromHexString(ADDRESS_THREE); + return this; + } + + // events + createEvent_NativeTokenDeposited( + senderAddress: string, + amount: string + ): NativeTokenDeposited { + let event = createNewNativeTokenDepositedEvent( + senderAddress, + amount, + this.id + ); + + return event; + } + + createEvent_Deposited( + senderAddress: string, + amount: string, + reference: string + ): Deposited { + if (!this.token) { + throw new Error('Token is null'); + } + + // we cast to string only for stoping rust compiler complaints. + let event = createNewDepositedEvent( + senderAddress, + this.token as string, + amount, + reference, + this.id + ); + + return event; + } + + createEvent_CallbackReceived( + onERC721Received: string, + functionData: Bytes + ): CallbackReceived { + if (!this.token) { + throw new Error('Token is null'); + } + + // we cast to string only for stoping rust compiler complaints. + let event = createCallbackReceivedEvent( + this.id, + Bytes.fromHexString(onERC721Received), + this.token as string, + functionData + ); + + return event; + } +} + +// Token Voting class TokenVotingVoterMethods extends TokenVotingVoter { withDefaultValues(): TokenVotingVoterMethods { this.id = Address.fromHexString(CONTRACT_ADDRESS) @@ -74,7 +324,7 @@ class TokenVotingVoterMethods extends TokenVotingVoter { .concat(ADDRESS_ONE); this.address = ADDRESS_ONE; this.plugin = Address.fromHexString(CONTRACT_ADDRESS).toHexString(); - this.lastUpdated = BigInt.fromString(ZERO); + this.lastUpdated = BigInt.zero(); return this; }