Skip to content

Commit

Permalink
feat: use common mocks and token calls generators (#527)
Browse files Browse the repository at this point in the history
* update commons version

* wip

* minor fix

* fix comments

* fix prettier

* fix comments

* add global constants

* fix yarn lock and update changelog

* add constants to dao v1 tests
  • Loading branch information
josemarinas authored Feb 16, 2024
1 parent 1130dfc commit 1f4aa06
Show file tree
Hide file tree
Showing 19 changed files with 113 additions and 163 deletions.
5 changes: 5 additions & 0 deletions packages/subgraph/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [UPCOMING]

### Changed

- Removed `createERC1155TokenCalls`, `createTokenCalls`, `createWrappedTokenCalls` and `createDummyActions` and use the equivalent functions `createERC20TokenCalls`, `createERC1155TokenCalls` and `createDummyAction` from `@aragon/sdk-commons-subgraph`
- Used `createDummyAction` from `@aragon/sdk-commons-subgraph`

## 1.4.0

### Added
Expand Down
2 changes: 1 addition & 1 deletion packages/subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
"typescript": "^4.9.5"
},
"dependencies": {
"@aragon/osx-commons-subgraph": "^0.0.3"
"@aragon/osx-commons-subgraph": "^0.0.4"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {generateMemberEntityId, generateVoteEntityId} from '../../utils/ids';
import {
generateActionEntityId,
generateEntityIdFromAddress,
generatePermissionEntityId,
generatePluginEntityId,
generateProposalEntityId,
} from '@aragon/osx-commons-subgraph';
Expand Down Expand Up @@ -117,7 +116,6 @@ export function handleVoteCast(event: VoteCast): void {
const pluginProposalId = event.params.proposalId;
const memberAddress = event.params.voter;
const pluginAddress = event.address;
const pluginEntityId = generatePluginEntityId(pluginAddress);
const memberEntityId = generateMemberEntityId(pluginAddress, memberAddress);

let proposalId = generateProposalEntityId(pluginAddress, pluginProposalId);
Expand Down
1 change: 0 additions & 1 deletion packages/subgraph/src/packages/multisig/multisig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
MultisigSettingsUpdated,
} from '../../../generated/templates/Multisig/Multisig';
import {generateMemberEntityId, generateVoterEntityId} from '../../utils/ids';
import {getProposalId} from '../../utils/proposals';
import {
generateActionEntityId,
generatePluginEntityId,
Expand Down
1 change: 0 additions & 1 deletion packages/subgraph/src/packages/token/token-voting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
generateActionEntityId,
generatePluginEntityId,
generateProposalEntityId,
generateEntityIdFromAddress,
} from '@aragon/osx-commons-subgraph';
import {BigInt, dataSource, DataSourceContext} from '@graphprotocol/graph-ts';

Expand Down
1 change: 0 additions & 1 deletion packages/subgraph/src/plugin/pluginRepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
Granted,
Revoked,
} from '../../generated/templates/PluginRepoTemplate/PluginRepo';
import {getPluginVersionId} from './utils';
import {
generatePermissionEntityId,
generatePluginReleaseEntityId,
Expand Down
2 changes: 1 addition & 1 deletion packages/subgraph/src/utils/tokens/erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {GovernanceWrappedERC20} from '../../../generated/templates/TokenVoting/G
import {GOVERNANCE_WRAPPED_ERC20_INTERFACE_ID} from '../../utils/constants';
import {supportsInterface} from '../erc165';
import {generateTokenEntityId} from '../ids';
import {ERC20_transfer, ERC20_transferFrom, getTransferId} from './common';
import {ERC20_transfer, ERC20_transferFrom} from './common';
import {
generateBalanceEntityId,
generateDaoEntityId,
Expand Down
2 changes: 1 addition & 1 deletion packages/subgraph/src/utils/tokens/eth.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {NativeBalance, NativeTransfer} from '../../../generated/schema';
import {ADDRESS_ZERO} from '../constants';
import {getTransferId, TransferType} from './common';
import {TransferType} from './common';
import {
generateBalanceEntityId,
generateDaoEntityId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {VOTING_MODES} from '../../src/utils/constants';
import {
generateMemberEntityId,
generateVoteEntityId,
generateVoterEntityId,
} from '../../src/utils/ids';
import {
ADDRESS_ONE,
Expand All @@ -37,11 +36,7 @@ import {
ALLOW_FAILURE_MAP,
PROPOSAL_ENTITY_ID,
} from '../constants';
import {
createDummyActions,
createGetProposalCall,
createTotalVotingPowerCall,
} from '../utils';
import {createGetProposalCall, createTotalVotingPowerCall} from '../utils';
import {
createNewMembersAddedEvent,
createNewVoteCastEvent,
Expand All @@ -53,13 +48,13 @@ import {
createAddresslistVotingProposalEntityState,
} from './utils';
import {
generateEntityIdFromAddress,
generatePluginEntityId,
createDummyAction,
} from '@aragon/osx-commons-subgraph';
import {Address, BigInt, Bytes, log} from '@graphprotocol/graph-ts';
import {Address, BigInt} from '@graphprotocol/graph-ts';
import {assert, clearStore, test} from 'matchstick-as/assembly/index';

let actions = createDummyActions(DAO_TOKEN_ADDRESS, '0', '0x00000000');
let actions = [createDummyAction(DAO_TOKEN_ADDRESS, '0', '0x00000000')];

const daoAddress = Address.fromString(DAO_ADDRESS);
const daoEntityId = generatePluginEntityId(daoAddress);
Expand Down
4 changes: 2 additions & 2 deletions packages/subgraph/tests/admin/admin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
START_DATE,
ALLOW_FAILURE_MAP,
} from '../constants';
import {createDummyActions} from '../utils';
import {
createNewProposalCreatedEvent,
createProposalExecutedEvent,
Expand All @@ -23,6 +22,7 @@ import {
generateDaoEntityId,
generatePluginEntityId,
generateProposalEntityId,
createDummyAction,
} from '@aragon/osx-commons-subgraph';
import {Address, BigInt, Bytes} from '@graphprotocol/graph-ts';
import {assert, clearStore, test} from 'matchstick-as/assembly/index';
Expand All @@ -43,7 +43,7 @@ test('Run Admin plugin (handleProposalCreated) mappings with mock event', () =>
adminPlugin.save();

// create event
let actions = createDummyActions(ADDRESS_TWO, actionValue, actionData);
let actions = [createDummyAction(ADDRESS_TWO, actionValue, actionData)];
let event = createNewProposalCreatedEvent(
PLUGIN_PROPOSAL_ID,
ADDRESS_ONE,
Expand Down
4 changes: 4 additions & 0 deletions packages/subgraph/tests/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export const HALF_ETH = '500000000000000000';

export const ERC20_AMOUNT_HALF = '10000';
export const ERC20_AMOUNT_FULL = '20000';
export const ERC20_TOTAL_SUPPLY = '10';
export const ERC20_DECIMALS = '6';
export const TOKEN_SYMBOL = 'symbol';
export const TOKEN_NAME = 'name';

export const HOUR = '3600';

Expand Down
33 changes: 22 additions & 11 deletions packages/subgraph/tests/dao/dao_v1_0_0.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ import {
ADDRESS_FOUR,
ERC20_AMOUNT_HALF,
ERC20_AMOUNT_FULL,
ERC20_TOTAL_SUPPLY,
TOKEN_NAME,
TOKEN_SYMBOL,
ERC20_DECIMALS,
} from '../constants';
import {
ExtendedDao,
Expand All @@ -59,11 +63,6 @@ import {
ExtendedNativeBalance,
ExtendedNativeTransfer,
} from '../helpers/extended-schema';
import {
createDummyActions,
createERC1155TokenCalls,
createTokenCalls,
} from '../utils';
import {
getBalanceOf,
createNewExecutedEvent,
Expand All @@ -81,6 +80,9 @@ import {
generateTokenIdBalanceEntityId,
generateTransactionActionsProposalEntityId,
generateTransferEntityId,
createDummyAction,
createERC20TokenCalls,
createERC1155TokenCalls,
} from '@aragon/osx-commons-subgraph';
import {Address, Bytes, BigInt, ethereum} from '@graphprotocol/graph-ts';
import {
Expand Down Expand Up @@ -120,13 +122,13 @@ function createExecutedEvent(
isDynamic
);

let action = createDummyActions(
let action = createDummyAction(
DAO_TOKEN_ADDRESS,
'0',
functionData.toHexString()
);

actions.push(action[0]);
actions.push(action);
}

if (execResults.length == 0) {
Expand Down Expand Up @@ -265,8 +267,6 @@ describe('handleDeposited: ', () => {
daoTokenContract.mockCall_balanceOf(DAO_ADDRESS, ERC20_AMOUNT_HALF);
daoTokenContract.mockCall_balanceOf(DAO_TOKEN_ADDRESS, ERC20_AMOUNT_HALF);

createTokenCalls(DAO_TOKEN_ADDRESS, 'DAO Token', 'DAOT', null, null);

getSupportsInterface(DAO_TOKEN_ADDRESS, ERC165_INTERFACE_ID, true);
getSupportsInterface(
DAO_TOKEN_ADDRESS,
Expand Down Expand Up @@ -993,7 +993,13 @@ describe('handleExecuted', () => {

describe('ERC20 action', () => {
beforeAll(() => {
createTokenCalls(DAO_TOKEN_ADDRESS, 'name', 'symbol', '6', '10');
createERC20TokenCalls(
DAO_TOKEN_ADDRESS,
ERC20_TOTAL_SUPPLY,
TOKEN_NAME,
TOKEN_SYMBOL,
ERC20_DECIMALS
);
getBalanceOf(DAO_TOKEN_ADDRESS, DAO_ADDRESS, ERC20_AMOUNT_HALF);
getBalanceOf(DAO_TOKEN_ADDRESS, DAO_TOKEN_ADDRESS, ERC20_AMOUNT_HALF);

Expand Down Expand Up @@ -1247,7 +1253,12 @@ describe('handleExecuted', () => {

describe('ERC721 action', () => {
beforeAll(() => {
createTokenCalls(DAO_TOKEN_ADDRESS, 'name', 'symbol', null, null);
createERC20TokenCalls(
DAO_TOKEN_ADDRESS,
ERC20_TOTAL_SUPPLY,
TOKEN_NAME,
TOKEN_SYMBOL
);

getSupportsInterface(DAO_TOKEN_ADDRESS, '0x01ffc9a7', true);
getSupportsInterface(DAO_TOKEN_ADDRESS, '80ac58cd', true);
Expand Down
54 changes: 36 additions & 18 deletions packages/subgraph/tests/dao/dao_v1_3_0.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,17 @@ import {
ERC20_AMOUNT_FULL,
CONTRACT_ADDRESS,
ZERO_BYTES32,
TOKEN_NAME,
TOKEN_SYMBOL,
ERC20_TOTAL_SUPPLY,
ERC20_DECIMALS,
} from '../constants';
import {
ExtendedERC1155Balance,
ExtendedERC1155Contract,
ExtendedERC1155TokenIdBalance,
ExtendedERC1155Transfer,
} from '../helpers/extended-schema';
import {
createDummyActions,
createERC1155TokenCalls,
createTokenCalls,
} from '../utils';
import {
createNewExecutedEvent,
encodeWithFunctionSelector,
Expand All @@ -54,6 +53,9 @@ import {
generateTokenIdBalanceEntityId,
generateTransactionActionsProposalEntityId,
generateTransferEntityId,
createDummyAction,
createERC20TokenCalls,
createERC1155TokenCalls,
} from '@aragon/osx-commons-subgraph';
import {ethereum, Bytes, Address, BigInt} from '@graphprotocol/graph-ts';
import {
Expand Down Expand Up @@ -250,7 +252,13 @@ describe('handleExecuted', () => {

describe('ERC20 action', () => {
beforeAll(() => {
createTokenCalls(DAO_TOKEN_ADDRESS, 'name', 'symbol', '6', '10');
createERC20TokenCalls(
DAO_TOKEN_ADDRESS,
ERC20_TOTAL_SUPPLY,
TOKEN_NAME,
TOKEN_SYMBOL,
ERC20_DECIMALS
);
getBalanceOf(DAO_TOKEN_ADDRESS, DAO_ADDRESS, ERC20_AMOUNT_HALF);
getBalanceOf(DAO_TOKEN_ADDRESS, DAO_TOKEN_ADDRESS, ERC20_AMOUNT_HALF);

Expand All @@ -267,7 +275,12 @@ describe('handleExecuted', () => {

describe('ERC20 transfer action', () => {
beforeAll(() => {
createTokenCalls(DAO_TOKEN_ADDRESS, 'name', 'symbol', null, null);
createERC20TokenCalls(
DAO_TOKEN_ADDRESS,
ERC20_TOTAL_SUPPLY,
TOKEN_NAME,
TOKEN_SYMBOL
);

getSupportsInterface(DAO_TOKEN_ADDRESS, ERC165_INTERFACE_ID, true);
getSupportsInterface(
Expand Down Expand Up @@ -315,8 +328,8 @@ describe('handleExecuted', () => {

// check ERC20Contract entity
eq('ERC20Contract', tokenEntityId, 'id', tokenEntityId);
eq('ERC20Contract', tokenEntityId, 'name', 'name');
eq('ERC20Contract', tokenEntityId, 'symbol', 'symbol');
eq('ERC20Contract', tokenEntityId, 'name', TOKEN_NAME);
eq('ERC20Contract', tokenEntityId, 'symbol', TOKEN_SYMBOL);
assert.entityCount('ERC20Contract', 1);

// check ERC20Balance entity
Expand Down Expand Up @@ -431,8 +444,8 @@ describe('handleExecuted', () => {

// check ERC20Contract entity
eq('ERC20Contract', tokenEntityId, 'id', tokenEntityId);
eq('ERC20Contract', tokenEntityId, 'name', 'name');
eq('ERC20Contract', tokenEntityId, 'symbol', 'symbol');
eq('ERC20Contract', tokenEntityId, 'name', TOKEN_NAME);
eq('ERC20Contract', tokenEntityId, 'symbol', TOKEN_SYMBOL);
assert.entityCount('ERC20Contract', 1);

// check ERC20Balance entity
Expand Down Expand Up @@ -510,7 +523,12 @@ describe('handleExecuted', () => {

describe('ERC721 action', () => {
beforeAll(() => {
createTokenCalls(DAO_TOKEN_ADDRESS, 'name', 'symbol', null, null);
createERC20TokenCalls(
DAO_TOKEN_ADDRESS,
ERC20_TOTAL_SUPPLY,
TOKEN_NAME,
TOKEN_SYMBOL
);

getSupportsInterface(DAO_TOKEN_ADDRESS, '0x01ffc9a7', true);
getSupportsInterface(DAO_TOKEN_ADDRESS, '80ac58cd', true);
Expand Down Expand Up @@ -570,8 +588,8 @@ describe('handleExecuted', () => {

// check ERC721Contract entity
eq('ERC721Contract', tokenEntityId, 'id', tokenEntityId);
eq('ERC721Contract', tokenEntityId, 'name', 'name');
eq('ERC721Contract', tokenEntityId, 'symbol', 'symbol');
eq('ERC721Contract', tokenEntityId, 'name', TOKEN_NAME);
eq('ERC721Contract', tokenEntityId, 'symbol', TOKEN_SYMBOL);
assert.entityCount('ERC721Contract', 1);

// check ERC721Balance entity
Expand Down Expand Up @@ -677,8 +695,8 @@ describe('handleExecuted', () => {

// check ERC721Contract entity
eq('ERC721Contract', tokenEntityId, 'id', tokenEntityId);
eq('ERC721Contract', tokenEntityId, 'name', 'name');
eq('ERC721Contract', tokenEntityId, 'symbol', 'symbol');
eq('ERC721Contract', tokenEntityId, 'name', TOKEN_NAME);
eq('ERC721Contract', tokenEntityId, 'symbol', TOKEN_SYMBOL);
assert.entityCount('ERC721Contract', 1);

// check ERC721Balance entity
Expand Down Expand Up @@ -1048,13 +1066,13 @@ function createExecutedEvent(
isDynamic
);

let action = createDummyActions(
let action = createDummyAction(
DAO_TOKEN_ADDRESS,
'0',
functionData.toHexString()
);

actions.push(action[0]);
actions.push(action);
}

if (execResults.length == 0) {
Expand Down
Loading

0 comments on commit 1f4aa06

Please sign in to comment.