Skip to content

Commit

Permalink
Clean linting
Browse files Browse the repository at this point in the history
  • Loading branch information
brickpop committed May 29, 2024
1 parent 850dfa8 commit 8828fd7
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 255 deletions.
249 changes: 0 additions & 249 deletions packages/contracts/test/helpers/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {expect} from 'chai';
import {BigNumber} from 'ethers';

export type VersionTag = {release: BigNumber; build: BigNumber};
Expand All @@ -8,251 +7,3 @@ export enum Operation {
Revoke,
GrantWithCondition,
}

export function getNamedTypesFromMetadata(inputs: any): string[] {
const types: string[] = [];

for (const input of inputs) {
if (input.type.startsWith('tuple')) {
const tupleResult = getNamedTypesFromMetadata(input.components).join(
', '
);

let tupleString = `tuple(${tupleResult})`;

if (input.type.endsWith('[]')) {
tupleString = tupleString.concat('[]');
}

types.push(tupleString);
} else if (input.type.endsWith('[]')) {
const baseType = input.type.slice(0, -2);
types.push(`${baseType}[] ${input.name}`);
} else {
types.push(`${input.type} ${input.name}`);
}
}

return types;
}

describe('getNamedTypesFromMetadata', function () {
it('simple', async () => {
const json = {
inputs: [
{
name: 'number',
type: 'uint256',
internalType: 'uint256',
},
{
name: 'account',
type: 'address',
internalType: 'address',
},
],
};

expect(getNamedTypesFromMetadata(json.inputs)).to.deep.equal([
'uint256 number',
'address account',
]);
});

it('array', async () => {
const json = {
inputs: [
{
internalType: 'address[]',
name: 'members',
type: 'address[]',
},
],
};

expect(getNamedTypesFromMetadata(json.inputs)).to.deep.equal([
'address[] members',
]);
});

it('struct', async () => {
const json = {
inputs: [
{
components: [
{
internalType: 'bool',
name: 'onlyListed',
type: 'bool',
},
{
internalType: 'uint16',
name: 'minApprovals',
type: 'uint16',
},
],
internalType: 'struct Multisig.MultisigSettings',
name: 'multisigSettings',
type: 'tuple',
},
],
};

expect(getNamedTypesFromMetadata(json.inputs)).to.deep.equal([
'tuple(bool onlyListed, uint16 minApprovals)',
]);
});

it('nested struct', async () => {
const json = {
inputs: [
{
components: [
{
internalType: 'bool',
name: 'var1',
type: 'bool',
},
{
components: [
{
internalType: 'bool',
name: 'var2',
type: 'bool',
},
{
internalType: 'uint16',
name: 'var3',
type: 'uint16',
},
{
components: [
{
internalType: 'bool',
name: 'var4',
type: 'bool',
},
{
internalType: 'uint16',
name: 'var5',
type: 'uint16',
},
{
internalType: 'bytes',
name: 'var6',
type: 'bytes',
},
],
internalType: 'struct Example',
name: 'layer3',
type: 'tuple',
},
],
internalType: 'struct Example',
name: 'layer2',
type: 'tuple',
},
],
internalType: 'struct Example',
name: 'layer1',
type: 'tuple',
},
],
};

expect(getNamedTypesFromMetadata(json.inputs)).to.deep.equal([
'tuple(bool var1, tuple(bool var2, uint16 var3, tuple(bool var4, uint16 var5, bytes var6)))',
]);
});

it('array of structs', async () => {
const json = {
inputs: [
{
components: [
{
internalType: 'address',
name: 'to',
type: 'address',
},
{
internalType: 'uint256',
name: 'value',
type: 'uint256',
},
{
internalType: 'bytes',
name: 'data',
type: 'bytes',
},
],
indexed: false,
internalType: 'struct IDAO.Action[]',
name: 'actions',
type: 'tuple[]',
},
],
};

expect(getNamedTypesFromMetadata(json.inputs)).to.deep.equal([
'tuple(address to, uint256 value, bytes data)[]',
]);
});

it('nested array of structs', async () => {
const json = {
inputs: [
{
components: [
{
internalType: 'address',
name: 'to',
type: 'address',
},
{
internalType: 'uint256',
name: 'value',
type: 'uint256',
},
{
internalType: 'bytes',
name: 'data',
type: 'bytes',
},
{
components: [
{
internalType: 'address',
name: 'to',
type: 'address',
},
{
internalType: 'uint256',
name: 'value',
type: 'uint256',
},
{
internalType: 'bytes',
name: 'data',
type: 'bytes',
},
],
indexed: false,
internalType: 'struct IDAO.Action[]',
name: 'actions',
type: 'tuple[]',
},
],
indexed: false,
internalType: 'struct IDAO.Action[]',
name: 'actions',
type: 'tuple[]',
},
],
};

expect(getNamedTypesFromMetadata(json.inputs)).to.deep.equal([
'tuple(address to, uint256 value, bytes data, tuple(address to, uint256 value, bytes data)[])[]',
]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {osxContracts} from '../../utils/helpers';
import {getPluginRepoInfo} from '../../utils/plugin-repo-info';
import {installPlugin, uninstallPlugin} from '../helpers/setup';
import {deployTestDao} from '../helpers/test-dao';
// import { getNamedTypesFromMetadata } from "../helpers/types";
import {
DAO,
PluginRepo__factory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import {
UPGRADE_PLUGIN_PERMISSION_ID,
ZERO_BYTES32,
} from '../unit-testing/common';
// import { getNamedTypesFromMetadata } from "../helpers/types";
import {
DAO,
PluginRepo__factory,
Expand Down
1 change: 0 additions & 1 deletion packages/contracts/test/integration-testing/space-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {getPluginRepoInfo} from '../../utils/plugin-repo-info';
import {installPlugin, uninstallPlugin} from '../helpers/setup';
import {deployTestDao} from '../helpers/test-dao';
import {ADDRESS_ZERO} from '../unit-testing/common';
// import { getNamedTypesFromMetadata } from "../helpers/types";
import {
DAO,
PluginRepo__factory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ describe('Member Access Condition', function () {
);

// 1
let [selector, who] =
const [selector, who] =
await testMemberAccessExecuteCondition.decodeAddMemberCalldata(
calldata
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
ADDRESS_ONE,
ADDRESS_TWO,
ADDRESS_ZERO,
advanceTime,
EMPTY_DATA,
EXECUTE_PERMISSION_ID,
mineBlock,
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/test/unit-testing/space-plugin-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '../../typechain';
import {getPluginSetupProcessorAddress} from '../../utils/helpers';
import {deployTestDao} from '../helpers/test-dao';
import {getNamedTypesFromMetadata, Operation} from '../helpers/types';
import {Operation} from '../helpers/types';
import {
ADDRESS_ONE,
ADDRESS_ZERO,
Expand Down

0 comments on commit 8828fd7

Please sign in to comment.