Skip to content

Commit

Permalink
Set primary terminal of done
Browse files Browse the repository at this point in the history
  • Loading branch information
odd-amphora committed Nov 25, 2021
1 parent 0ea391c commit d81ee54
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
3 changes: 1 addition & 2 deletions test/jb_directory/add_terminals.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import jbOperatoreStore from "../../artifacts/contracts/JBOperatorStore.sol/JBOp
import jbProjects from "../../artifacts/contracts/JBProjects.sol/JBProjects.json";
import jbTerminal from "../../artifacts/contracts/interfaces/IJBTerminal.sol/IJBTerminal.json";

// TODO(odd-amphora): Consider adding separate permissions tests; though we may want to fold these
// into JBOperatable tests.
// TODO(odd-amphora): Permissions.
describe('JBDirectory::addTerminalsOf(...)', function () {
const PROJECT_ID = 13;

Expand Down
29 changes: 27 additions & 2 deletions test/jb_directory/set_primary_terminal_of.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import jbOperatoreStore from "../../artifacts/contracts/JBOperatorStore.sol/JBOp
import jbProjects from "../../artifacts/contracts/JBProjects.sol/JBProjects.json";
import jbTerminal from "../../artifacts/contracts/interfaces/IJBTerminal.sol/IJBTerminal.json";

// TODO(odd-amphora): Permissions.
describe('JBDirectory::setPrimaryTerminalOf(...)', function () {
const PROJECT_ID = 13;

Expand Down Expand Up @@ -40,17 +41,21 @@ describe('JBDirectory::setPrimaryTerminalOf(...)', function () {
return { caller, deployer, addrs, jbDirectory, terminal1, terminal2 };
}

it('Can\t set terminal with address(0)', async function () {
it(`Can't set primary terminal with address(0)`, async function () {
const { caller, jbDirectory } = await setup();

await expect(
jbDirectory.connect(caller).setPrimaryTerminalOf(PROJECT_ID, ethers.constants.AddressZero)
).to.be.revertedWith('0x2e: ZERO_ADDRESS');
});

it('Setting primary terminal should emit event', async function () {
it('Setting primary terminal should emit an event and be added to terminals', async function () {
const { caller, jbDirectory, terminal1 } = await setup();

// Initially no terminals should be set.
let initialTerminals = [...(await jbDirectory.connect(caller).terminalsOf(PROJECT_ID))];
expect(initialTerminals.length).to.equal(0);

const terminal1TokenAddress = ethers.Wallet.createRandom().address;
await terminal1.mock.token.returns(terminal1TokenAddress);

Expand All @@ -64,6 +69,26 @@ describe('JBDirectory::setPrimaryTerminalOf(...)', function () {
caller.address
)

let resultTerminals = [...(await jbDirectory.connect(caller).terminalsOf(PROJECT_ID))];
resultTerminals.sort();

// After the primary terminal is set it should be added to the project.
let expectedTerminals = [terminal1.address];
expectedTerminals.sort();

expect(resultTerminals).to.eql(expectedTerminals)
});

it(`Can't set the same primary terminal twice in a row`, async function () {
const { caller, jbDirectory, terminal1, terminal2 } = await setup();

await terminal1.mock.token.returns(ethers.Wallet.createRandom().address);

// Should succeed on the first attempt and then fail on the second.
await jbDirectory.connect(caller).setPrimaryTerminalOf(PROJECT_ID, terminal1.address);
await expect(
jbDirectory.connect(caller).setPrimaryTerminalOf(PROJECT_ID, terminal1.address)
).to.be.revertedWith('0x2f: ALREADY_SET');
});

});

0 comments on commit d81ee54

Please sign in to comment.