Skip to content

Commit

Permalink
Test uninstall behavior using EtherRouter
Browse files Browse the repository at this point in the history
  • Loading branch information
kronosapiens committed Jun 20, 2024
1 parent 2ef4ba3 commit db46709
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 66 deletions.
12 changes: 6 additions & 6 deletions test/extensions/coin-machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const {
currentBlockTime,
forwardTimeTo,
expectEvent,
web3GetStorageAt,
} = require("../../helpers/test-helper");

const { setupRandomToken, setupRandomColony, setupColony, getMetaTransactionParameters } = require("../../helpers/test-data-generator");
Expand Down Expand Up @@ -98,17 +97,18 @@ contract("Coin Machine", (accounts) => {
({ colony } = await setupRandomColony(colonyNetwork));
await colony.installExtension(COIN_MACHINE, version, { from: USER0 });

const coinMachineAddress = await colonyNetwork.getExtensionInstallation(COIN_MACHINE, colony.address);
let resolverAddress = await web3GetStorageAt(coinMachineAddress, 2);
expect(resolverAddress).to.not.equal(ethers.constants.HashZero);
const extensionAddress = await colonyNetwork.getExtensionInstallation(COIN_MACHINE, colony.address);
const etherRouter = await EtherRouter.at(extensionAddress);
let resolverAddress = await etherRouter.resolver();
expect(resolverAddress).to.not.equal(ethers.constants.AddressZero);

await checkErrorRevert(colony.installExtension(COIN_MACHINE, version, { from: USER0 }), "colony-network-extension-already-installed");
await checkErrorRevert(colony.uninstallExtension(COIN_MACHINE, { from: USER1 }), "ds-auth-unauthorized");

await colony.uninstallExtension(COIN_MACHINE, { from: USER0 });

resolverAddress = await web3GetStorageAt(coinMachineAddress, 2);
expect(resolverAddress).to.equal(ethers.constants.HashZero);
resolverAddress = await etherRouter.resolver();
expect(resolverAddress).to.equal(ethers.constants.AddressZero);
});

it("can send unsold tokens back to the colony", async () => {
Expand Down
13 changes: 7 additions & 6 deletions test/extensions/evaluated-expenditure.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { ethers } = require("ethers");
const { soliditySha3 } = require("web3-utils");

const { UINT256_MAX, WAD, ADDRESS_ZERO, ADDRESS_FULL, SLOT0 } = require("../../helpers/constants");
const { checkErrorRevert, web3GetStorageAt } = require("../../helpers/test-helper");
const { checkErrorRevert } = require("../../helpers/test-helper");
const { setupRandomColony, getMetaTransactionParameters } = require("../../helpers/test-data-generator");

const { expect } = chai;
Expand Down Expand Up @@ -73,17 +73,18 @@ contract("EvaluatedExpenditure", (accounts) => {
({ colony } = await setupRandomColony(colonyNetwork));
await colony.installExtension(EVALUATED_EXPENDITURE, version, { from: USER0 });

const evaluatedExpenditureAddress = await colonyNetwork.getExtensionInstallation(EVALUATED_EXPENDITURE, colony.address);
let resolverAddress = await web3GetStorageAt(evaluatedExpenditureAddress, 2);
expect(resolverAddress).to.not.equal(ethers.constants.HashZero);
const extensionAddress = await colonyNetwork.getExtensionInstallation(EVALUATED_EXPENDITURE, colony.address);
const etherRouter = await EtherRouter.at(extensionAddress);
let resolverAddress = await etherRouter.resolver();
expect(resolverAddress).to.not.equal(ethers.constants.AddressZero);

await checkErrorRevert(colony.installExtension(EVALUATED_EXPENDITURE, version, { from: USER0 }), "colony-network-extension-already-installed");
await checkErrorRevert(colony.uninstallExtension(EVALUATED_EXPENDITURE, { from: USER1 }), "ds-auth-unauthorized");

await colony.uninstallExtension(EVALUATED_EXPENDITURE, { from: USER0 });

resolverAddress = await web3GetStorageAt(evaluatedExpenditureAddress, 2);
expect(resolverAddress).to.equal(ethers.constants.HashZero);
resolverAddress = await etherRouter.resolver();
expect(resolverAddress).to.equal(ethers.constants.AddressZero);
});

it("can't use the network-level functions if installed via ColonyNetwork", async () => {
Expand Down
12 changes: 6 additions & 6 deletions test/extensions/funding-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const {
forwardTime,
getBlockTime,
removeSubdomainLimit,
web3GetStorageAt,
} = require("../../helpers/test-helper");

const { setupRandomColony, getMetaTransactionParameters } = require("../../helpers/test-data-generator");
Expand Down Expand Up @@ -201,17 +200,18 @@ contract("Funding Queues", (accounts) => {
({ colony } = await setupRandomColony(colonyNetwork));
await colony.installExtension(FUNDING_QUEUE, version, { from: USER0 });

const fundingQueueAddress = await colonyNetwork.getExtensionInstallation(FUNDING_QUEUE, colony.address);
let resolverAddress = await web3GetStorageAt(fundingQueueAddress, 2);
expect(resolverAddress).to.not.equal(ethers.constants.HashZero);
const extensionAddress = await colonyNetwork.getExtensionInstallation(FUNDING_QUEUE, colony.address);
const etherRouter = await EtherRouter.at(extensionAddress);
let resolverAddress = await etherRouter.resolver();
expect(resolverAddress).to.not.equal(ethers.constants.AddressZero);

await checkErrorRevert(colony.installExtension(FUNDING_QUEUE, version, { from: USER0 }), "colony-network-extension-already-installed");
await checkErrorRevert(colony.uninstallExtension(FUNDING_QUEUE, { from: USER1 }), "ds-auth-unauthorized");

await colony.uninstallExtension(FUNDING_QUEUE, { from: USER0 });

resolverAddress = await web3GetStorageAt(fundingQueueAddress, 2);
expect(resolverAddress).to.equal(ethers.constants.HashZero);
resolverAddress = await etherRouter.resolver();
expect(resolverAddress).to.equal(ethers.constants.AddressZero);
});

it("can't use the network-level functions if installed via ColonyNetwork", async () => {
Expand Down
13 changes: 7 additions & 6 deletions test/extensions/one-tx-payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const {
SECONDS_PER_DAY,
} = require("../../helpers/constants");

const { checkErrorRevert, rolesToBytes32, expectEvent, upgradeColonyOnceThenToLatest, web3GetStorageAt } = require("../../helpers/test-helper");
const { checkErrorRevert, rolesToBytes32, expectEvent, upgradeColonyOnceThenToLatest } = require("../../helpers/test-helper");
const { setupRandomColony, fundColonyWithTokens, getMetaTransactionParameters, setupColony } = require("../../helpers/test-data-generator");

const { expect } = chai;
Expand Down Expand Up @@ -106,17 +106,18 @@ contract("One transaction payments", (accounts) => {
({ colony } = await setupRandomColony(colonyNetwork));
await colony.installExtension(ONE_TX_PAYMENT, version, { from: USER0 });

const oneTxPaymentAddress = await colonyNetwork.getExtensionInstallation(ONE_TX_PAYMENT, colony.address);
let resolverAddress = await web3GetStorageAt(oneTxPaymentAddress, 2);
expect(resolverAddress).to.not.equal(ethers.constants.HashZero);
const extensionAddress = await colonyNetwork.getExtensionInstallation(ONE_TX_PAYMENT, colony.address);
const etherRouter = await EtherRouter.at(extensionAddress);
let resolverAddress = await etherRouter.resolver();
expect(resolverAddress).to.not.equal(ethers.constants.AddressZero);

await checkErrorRevert(colony.installExtension(ONE_TX_PAYMENT, version, { from: USER0 }), "colony-network-extension-already-installed");
await checkErrorRevert(colony.uninstallExtension(ONE_TX_PAYMENT, { from: USER1 }), "ds-auth-unauthorized");

await colony.uninstallExtension(ONE_TX_PAYMENT, { from: USER0 });

resolverAddress = await web3GetStorageAt(oneTxPaymentAddress, 2);
expect(resolverAddress).to.equal(ethers.constants.HashZero);
resolverAddress = await etherRouter.resolver();
expect(resolverAddress).to.equal(ethers.constants.AddressZero);
});

it("can't use the network-level functions if installed via ColonyNetwork", async () => {
Expand Down
13 changes: 7 additions & 6 deletions test/extensions/reputation-bootstrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { ethers } = require("ethers");
const { soliditySha3 } = require("web3-utils");

const { WAD, INT128_MAX, ADDRESS_ZERO, ADDRESS_FULL, SECONDS_PER_DAY, SECONDS_PER_HOUR } = require("../../helpers/constants");
const { checkErrorRevert, getBlockTime, forwardTime, web3GetStorageAt } = require("../../helpers/test-helper");
const { checkErrorRevert, getBlockTime, forwardTime } = require("../../helpers/test-helper");
const { setupRandomColony, getMetaTransactionParameters } = require("../../helpers/test-data-generator");

const { expect } = chai;
Expand Down Expand Up @@ -82,9 +82,10 @@ contract("Reputation Bootstrapper", (accounts) => {
({ colony } = await setupRandomColony(colonyNetwork));
await colony.installExtension(REPUTATION_BOOTSTRAPPER, version, { from: USER0 });

const reputationBoostrapperAddress = await colonyNetwork.getExtensionInstallation(REPUTATION_BOOTSTRAPPER, colony.address);
let resolverAddress = await web3GetStorageAt(reputationBoostrapperAddress, 2);
expect(resolverAddress).to.not.equal(ethers.constants.HashZero);
const extensionAddress = await colonyNetwork.getExtensionInstallation(REPUTATION_BOOTSTRAPPER, colony.address);
const etherRouter = await EtherRouter.at(extensionAddress);
let resolverAddress = await etherRouter.resolver();
expect(resolverAddress).to.not.equal(ethers.constants.AddressZero);

await checkErrorRevert(
colony.installExtension(REPUTATION_BOOTSTRAPPER, version, { from: USER0 }),
Expand All @@ -94,8 +95,8 @@ contract("Reputation Bootstrapper", (accounts) => {

await colony.uninstallExtension(REPUTATION_BOOTSTRAPPER, { from: USER0 });

resolverAddress = await web3GetStorageAt(reputationBoostrapperAddress, 2);
expect(resolverAddress).to.equal(ethers.constants.HashZero);
resolverAddress = await etherRouter.resolver();
expect(resolverAddress).to.equal(ethers.constants.AddressZero);
});

it("can't use the network-level functions if installed via ColonyNetwork", async () => {
Expand Down
12 changes: 6 additions & 6 deletions test/extensions/staged-expenditure.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const {
makeReputationValue,
getActiveRepCycle,
forwardTime,
web3GetStorageAt,
} = require("../../helpers/test-helper");

const PatriciaTree = require("../../packages/reputation-miner/patricia");
Expand Down Expand Up @@ -107,17 +106,18 @@ contract("Staged Expenditure", (accounts) => {
({ colony } = await setupRandomColony(colonyNetwork));
await colony.installExtension(STAGED_EXPENDITURE, version, { from: USER0 });

const stagedExpenditureAddress = await colonyNetwork.getExtensionInstallation(STAGED_EXPENDITURE, colony.address);
let resolverAddress = await web3GetStorageAt(stagedExpenditureAddress, 2);
expect(resolverAddress).to.not.equal(ethers.constants.HashZero);
const extensionAddress = await colonyNetwork.getExtensionInstallation(STAGED_EXPENDITURE, colony.address);
const etherRouter = await EtherRouter.at(extensionAddress);
let resolverAddress = await etherRouter.resolver();
expect(resolverAddress).to.not.equal(ethers.constants.AddressZero);

await checkErrorRevert(colony.installExtension(STAGED_EXPENDITURE, version, { from: USER0 }), "colony-network-extension-already-installed");
await checkErrorRevert(colony.uninstallExtension(STAGED_EXPENDITURE, { from: USER1 }), "ds-auth-unauthorized");

await colony.uninstallExtension(STAGED_EXPENDITURE, { from: USER0 });

resolverAddress = await web3GetStorageAt(stagedExpenditureAddress, 2);
expect(resolverAddress).to.equal(ethers.constants.HashZero);
resolverAddress = await etherRouter.resolver();
expect(resolverAddress).to.equal(ethers.constants.AddressZero);
});
});

Expand Down
12 changes: 6 additions & 6 deletions test/extensions/staked-expenditure.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const {
forwardTime,
expectEvent,
expectNoEvent,
web3GetStorageAt,
} = require("../../helpers/test-helper");

const PatriciaTree = require("../../packages/reputation-miner/patricia");
Expand Down Expand Up @@ -153,17 +152,18 @@ contract("StakedExpenditure", (accounts) => {
({ colony } = await setupRandomColony(colonyNetwork));
await colony.installExtension(STAKED_EXPENDITURE, version, { from: USER0 });

const stakedExpenditureAddress = await colonyNetwork.getExtensionInstallation(STAKED_EXPENDITURE, colony.address);
let resolverAddress = await web3GetStorageAt(stakedExpenditureAddress, 2);
expect(resolverAddress).to.not.equal(ethers.constants.HashZero);
const extensionAddress = await colonyNetwork.getExtensionInstallation(STAKED_EXPENDITURE, colony.address);
const etherRouter = await EtherRouter.at(extensionAddress);
let resolverAddress = await etherRouter.resolver();
expect(resolverAddress).to.not.equal(ethers.constants.AddressZero);

await checkErrorRevert(colony.installExtension(STAKED_EXPENDITURE, version, { from: USER0 }), "colony-network-extension-already-installed");
await checkErrorRevert(colony.uninstallExtension(STAKED_EXPENDITURE, { from: USER1 }), "ds-auth-unauthorized");

await colony.uninstallExtension(STAKED_EXPENDITURE, { from: USER0 });

resolverAddress = await web3GetStorageAt(stakedExpenditureAddress, 2);
expect(resolverAddress).to.equal(ethers.constants.HashZero);
resolverAddress = await etherRouter.resolver();
expect(resolverAddress).to.equal(ethers.constants.AddressZero);
});

it("setStakeFraction will emit the correct event if stakeFraction == 0", async () => {
Expand Down
13 changes: 7 additions & 6 deletions test/extensions/streaming-payments.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { ethers } = require("ethers");
const { soliditySha3 } = require("web3-utils");

const { UINT256_MAX, WAD, SECONDS_PER_DAY, ADDRESS_ZERO, ADDRESS_FULL } = require("../../helpers/constants");
const { checkErrorRevert, expectEvent, makeTxAtTimestamp, getBlockTime, forwardTime, web3GetStorageAt } = require("../../helpers/test-helper");
const { checkErrorRevert, expectEvent, makeTxAtTimestamp, getBlockTime, forwardTime } = require("../../helpers/test-helper");
const { setupRandomColony, fundColonyWithTokens } = require("../../helpers/test-data-generator");

const { expect } = chai;
Expand Down Expand Up @@ -82,17 +82,18 @@ contract("Streaming Payments", (accounts) => {
({ colony } = await setupRandomColony(colonyNetwork));
await colony.installExtension(STREAMING_PAYMENTS, version, { from: USER0 });

const streamingPaymentsAddress = await colonyNetwork.getExtensionInstallation(STREAMING_PAYMENTS, colony.address);
let resolverAddress = await web3GetStorageAt(streamingPaymentsAddress, 2);
expect(resolverAddress).to.not.equal(ethers.constants.HashZero);
const extensionAddress = await colonyNetwork.getExtensionInstallation(STREAMING_PAYMENTS, colony.address);
const etherRouter = await EtherRouter.at(extensionAddress);
let resolverAddress = await etherRouter.resolver();
expect(resolverAddress).to.not.equal(ethers.constants.AddressZero);

await checkErrorRevert(colony.installExtension(STREAMING_PAYMENTS, version, { from: USER0 }), "colony-network-extension-already-installed");
await checkErrorRevert(colony.uninstallExtension(STREAMING_PAYMENTS, { from: USER1 }), "ds-auth-unauthorized");

await colony.uninstallExtension(STREAMING_PAYMENTS, { from: USER0 });

resolverAddress = await web3GetStorageAt(streamingPaymentsAddress, 2);
expect(resolverAddress).to.equal(ethers.constants.HashZero);
resolverAddress = await etherRouter.resolver();
expect(resolverAddress).to.equal(ethers.constants.AddressZero);
});

it("can't use the network-level functions if installed via ColonyNetwork", async () => {
Expand Down
13 changes: 7 additions & 6 deletions test/extensions/token-supplier.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { soliditySha3 } = require("web3-utils");

const { UINT256_MAX, WAD, SECONDS_PER_DAY, ADDRESS_ZERO, ADDRESS_FULL } = require("../../helpers/constants");
const { setupRandomColony, getMetaTransactionParameters } = require("../../helpers/test-data-generator");
const { checkErrorRevert, currentBlockTime, makeTxAtTimestamp, getBlockTime, forwardTime, web3GetStorageAt } = require("../../helpers/test-helper");
const { checkErrorRevert, currentBlockTime, makeTxAtTimestamp, getBlockTime, forwardTime } = require("../../helpers/test-helper");

const { expect } = chai;
chai.use(bnChai(web3.utils.BN));
Expand Down Expand Up @@ -77,17 +77,18 @@ contract("Token Supplier", (accounts) => {
({ colony } = await setupRandomColony(colonyNetwork));
await colony.installExtension(TOKEN_SUPPLIER, version, { from: USER0 });

const tokenSupplierAddress = await colonyNetwork.getExtensionInstallation(TOKEN_SUPPLIER, colony.address);
let resolverAddress = await web3GetStorageAt(tokenSupplierAddress, 2);
expect(resolverAddress).to.not.equal(ethers.constants.HashZero);
const extensionAddress = await colonyNetwork.getExtensionInstallation(TOKEN_SUPPLIER, colony.address);
const etherRouter = await EtherRouter.at(extensionAddress);
let resolverAddress = await etherRouter.resolver();
expect(resolverAddress).to.not.equal(ethers.constants.AddressZero);

await checkErrorRevert(colony.installExtension(TOKEN_SUPPLIER, version, { from: USER0 }), "colony-network-extension-already-installed");
await checkErrorRevert(colony.uninstallExtension(TOKEN_SUPPLIER, { from: USER1 }), "ds-auth-unauthorized");

await colony.uninstallExtension(TOKEN_SUPPLIER, { from: USER0 });

resolverAddress = await web3GetStorageAt(tokenSupplierAddress, 2);
expect(resolverAddress).to.equal(ethers.constants.HashZero);
resolverAddress = await etherRouter.resolver();
expect(resolverAddress).to.equal(ethers.constants.AddressZero);
});

it("can initialise", async () => {
Expand Down
12 changes: 6 additions & 6 deletions test/extensions/voting-rep.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ const {
expectEvent,
getTokenArgs,
getBlockTime,
web3GetStorageAt,
} = require("../../helpers/test-helper");

const { setupRandomColony, getMetaTransactionParameters, fundColonyWithTokens } = require("../../helpers/test-data-generator");
Expand Down Expand Up @@ -302,17 +301,18 @@ contract("Voting Reputation", (accounts) => {
({ colony } = await setupRandomColony(colonyNetwork));
await colony.installExtension(VOTING_REPUTATION, version, { from: USER0 });

const votingAddress = await colonyNetwork.getExtensionInstallation(VOTING_REPUTATION, colony.address);
let resolverAddress = await web3GetStorageAt(votingAddress, 2);
expect(resolverAddress).to.not.equal(ethers.constants.HashZero);
const extensionAddress = await colonyNetwork.getExtensionInstallation(VOTING_REPUTATION, colony.address);
const etherRouter = await EtherRouter.at(extensionAddress);
let resolverAddress = await etherRouter.resolver();
expect(resolverAddress).to.not.equal(ethers.constants.AddressZero);

await checkErrorRevert(colony.installExtension(VOTING_REPUTATION, version, { from: USER0 }), "colony-network-extension-already-installed");
await checkErrorRevert(colony.uninstallExtension(VOTING_REPUTATION, { from: USER1 }), "ds-auth-unauthorized");

await colony.uninstallExtension(VOTING_REPUTATION, { from: USER0 });

resolverAddress = await web3GetStorageAt(votingAddress, 2);
expect(resolverAddress).to.equal(ethers.constants.HashZero);
resolverAddress = await etherRouter.resolver();
expect(resolverAddress).to.equal(ethers.constants.AddressZero);
});

it("can deprecate the extension if root", async () => {
Expand Down
Loading

0 comments on commit db46709

Please sign in to comment.