Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use common mocks and token calls generators #527

Merged
merged 9 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 from `@aragon/sdk-commons-subgraph`
josemarinas marked this conversation as resolved.
Show resolved Hide resolved
- 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
18 changes: 7 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 @@ -59,11 +59,6 @@ import {
ExtendedNativeBalance,
ExtendedNativeTransfer,
} from '../helpers/extended-schema';
import {
createDummyActions,
createERC1155TokenCalls,
createTokenCalls,
} from '../utils';
import {
getBalanceOf,
createNewExecutedEvent,
Expand All @@ -81,6 +76,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 +118,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 +263,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 +989,7 @@ describe('handleExecuted', () => {

describe('ERC20 action', () => {
beforeAll(() => {
createTokenCalls(DAO_TOKEN_ADDRESS, 'name', 'symbol', '6', '10');
createERC20TokenCalls(DAO_TOKEN_ADDRESS, '10', 'name', 'symbol', '6');
josemarinas marked this conversation as resolved.
Show resolved Hide resolved
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 +1243,7 @@ describe('handleExecuted', () => {

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

getSupportsInterface(DAO_TOKEN_ADDRESS, '0x01ffc9a7', true);
getSupportsInterface(DAO_TOKEN_ADDRESS, '80ac58cd', true);
Expand Down
26 changes: 16 additions & 10 deletions packages/subgraph/tests/dao/dao_v1_3_0.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ import {
ExtendedERC1155TokenIdBalance,
ExtendedERC1155Transfer,
} from '../helpers/extended-schema';
import {
createDummyActions,
createERC1155TokenCalls,
createTokenCalls,
} from '../utils';
import {
createNewExecutedEvent,
encodeWithFunctionSelector,
Expand All @@ -54,6 +49,9 @@ import {
generateTokenIdBalanceEntityId,
generateTransactionActionsProposalEntityId,
generateTransferEntityId,
createDummyAction,
createERC20TokenCalls,
createERC1155TokenCalls,
} from '@aragon/osx-commons-subgraph';
import {ethereum, Bytes, Address, BigInt} from '@graphprotocol/graph-ts';
import {
Expand All @@ -72,6 +70,8 @@ let tokenAddress = Address.fromString(DAO_TOKEN_ADDRESS);
let daoEntityId = generateDaoEntityId(daoAddress);
let tokenEntityId = generateTokenEntityId(tokenAddress);
let balanceEntityId = generateBalanceEntityId(daoAddress, tokenAddress);
const totalSupply = '10';
const decimals = '6';

describe('handleExecuted', () => {
afterEach(() => {
Expand Down Expand Up @@ -250,7 +250,13 @@ describe('handleExecuted', () => {

describe('ERC20 action', () => {
beforeAll(() => {
createTokenCalls(DAO_TOKEN_ADDRESS, 'name', 'symbol', '6', '10');
createERC20TokenCalls(
DAO_TOKEN_ADDRESS,
totalSupply,
'name',
'symbol',
decimals
);
josemarinas marked this conversation as resolved.
Show resolved Hide resolved
getBalanceOf(DAO_TOKEN_ADDRESS, DAO_ADDRESS, ERC20_AMOUNT_HALF);
getBalanceOf(DAO_TOKEN_ADDRESS, DAO_TOKEN_ADDRESS, ERC20_AMOUNT_HALF);

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

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

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

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

getSupportsInterface(DAO_TOKEN_ADDRESS, '0x01ffc9a7', true);
getSupportsInterface(DAO_TOKEN_ADDRESS, '80ac58cd', true);
Expand Down Expand Up @@ -1048,13 +1054,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
42 changes: 23 additions & 19 deletions packages/subgraph/tests/helpers/method-classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,15 @@ import {
delegatesCall,
getProposalCountCall,
} from '../token/utils';
import {
createGetProposalCall,
createTotalVotingPowerCall,
createTokenCalls,
createWrappedTokenCalls,
createERC1155TokenCalls,
} from '../utils';
import {createGetProposalCall, createTotalVotingPowerCall} from '../utils';
import {
generateEntityIdFromAddress,
generatePermissionEntityId,
generatePluginEntityId,
createERC20TokenCalls,
createERC1155TokenCalls,
createWrappedERC20TokenCalls,
createTokenCalls,
} from '@aragon/osx-commons-subgraph';
import {
Address,
Expand Down Expand Up @@ -275,13 +273,11 @@ class ERC721ContractMethods extends ERC721Contract {
if (!this.symbol) {
throw new Error('Symbol is null');
}
// we cast to string only for stoping rust compiler complaints.
// we cast to string only for stopping rust compiler complaints.
createTokenCalls(
this.id,
DAO_TOKEN_ADDRESS,
this.name as string,
this.symbol as string,
null,
null
this.symbol as string
);
}
}
Expand Down Expand Up @@ -341,13 +337,17 @@ class ERC20WrapperContractMethods extends ERC20WrapperContract {
} else if (!this.underlyingToken) {
throw new Error('Underlying token is null');
}
let supply = '10';
if (totalSupply) {
supply = totalSupply;
}

createWrappedTokenCalls(
createWrappedERC20TokenCalls(
this.id,
this.name as string,
this.symbol as string,
this.underlyingToken,
totalSupply
supply,
this.name as string,
this.symbol as string
);
}

Expand Down Expand Up @@ -378,13 +378,17 @@ class ERC20ContractMethods extends ERC20Contract {
if (!this.symbol) {
throw new Error('Symbol is null');
}
let supply = '10';
if (totalSupply) {
supply = totalSupply;
}
// we cast to string only for stoping rust compiler complaints.
josemarinas marked this conversation as resolved.
Show resolved Hide resolved
createTokenCalls(
createERC20TokenCalls(
this.id,
supply,
this.name as string,
this.symbol as string,
this.decimals.toString(),
totalSupply
this.decimals.toString()
);
}

Expand Down
6 changes: 2 additions & 4 deletions packages/subgraph/tests/multisig/multisig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
END_DATE,
ALLOW_FAILURE_MAP,
} from '../constants';
import {createDummyActions} from '../utils';
import {
createNewMembersAddedEvent,
createNewApprovedEvent,
Expand All @@ -43,16 +42,15 @@ import {
import {
generatePluginEntityId,
generateProposalEntityId,
createDummyAction,
} from '@aragon/osx-commons-subgraph';
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 pluginAddress = Address.fromString(CONTRACT_ADDRESS);
const pluginEntityId = generatePluginEntityId(pluginAddress);
const daoAddress = Address.fromString(DAO_ADDRESS);
const daoEntityId = generatePluginEntityId(daoAddress);
const pluginProposalId = BigInt.fromString(PLUGIN_PROPOSAL_ID);

test('Run Multisig (handleProposalCreated) mappings with mock event', () => {
Expand Down
Loading
Loading