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

Increased Delegate test coverage to 100% #1325

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Changes from all 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
79 changes: 79 additions & 0 deletions source/delegate/test/Delegate.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ describe('Delegate Unit', () => {
expect(await delegate.swapERC20()).to.equal(UPDATE_SWAP_ERC20_ADDRESS)
})

it('the swapERC20Contract address cannot be address(0)', async () => {
await expect(
delegate.setSwapERC20Contract(ADDRESS_ZERO)
).to.be.revertedWith('InvalidAddress')
})

it('only the owner can set the swapERC20Contract address', async () => {
await expect(
delegate.connect(anyone).setSwapERC20Contract(UPDATE_SWAP_ERC20_ADDRESS)
Expand Down Expand Up @@ -212,6 +218,37 @@ describe('Delegate Unit', () => {
)
})

it('an unauthorized manager cannot set a rule', async () => {
await delegate.connect(sender).authorize(manager.address)
await expect(
delegate
.connect(signer)
.setRule(
sender.address,
senderToken.address,
DEFAULT_SENDER_AMOUNT,
signerToken.address,
DEFAULT_SIGNER_AMOUNT,
RULE_EXPIRY
)
).to.be.revertedWith('SenderInvalid')
})

it('a manager cannot set a rule without prior authorization', async () => {
await expect(
delegate
.connect(manager)
.setRule(
sender.address,
senderToken.address,
DEFAULT_SENDER_AMOUNT,
signerToken.address,
DEFAULT_SIGNER_AMOUNT,
RULE_EXPIRY
)
).to.be.revertedWith('SenderInvalid')
})

it('a manager can unset a Rule', async () => {
await delegate.connect(sender).authorize(manager.address)
await delegate
Expand All @@ -234,6 +271,48 @@ describe('Delegate Unit', () => {
.withArgs(sender.address, senderToken.address, signerToken.address)
})

it('an unauthorized manager cannot unset a rule', async () => {
await delegate.connect(sender).authorize(manager.address)
await delegate
.connect(manager)
.setRule(
sender.address,
senderToken.address,
DEFAULT_SENDER_AMOUNT,
signerToken.address,
DEFAULT_SIGNER_AMOUNT,
RULE_EXPIRY
)

await expect(
delegate
.connect(signer)
.unsetRule(sender.address, senderToken.address, signerToken.address)
).to.be.revertedWith('SenderInvalid')
})

it('a revoked manager cannot unset a rule', async () => {
await delegate.connect(sender).authorize(manager.address)
await delegate
.connect(manager)
.setRule(
sender.address,
senderToken.address,
DEFAULT_SENDER_AMOUNT,
signerToken.address,
DEFAULT_SIGNER_AMOUNT,
RULE_EXPIRY
)

await delegate.connect(sender).revoke()

await expect(
delegate
.connect(manager)
.unsetRule(sender.address, senderToken.address, signerToken.address)
).to.be.revertedWith('SenderInvalid')
})

it('setting a Rule updates the rule balance', async () => {
await delegate
.connect(sender)
Expand Down
Loading