Skip to content

Commit

Permalink
test: add extra tests in LSP7 for transfers as operators
Browse files Browse the repository at this point in the history
  • Loading branch information
CJ42 committed Sep 27, 2023
1 parent 67149d0 commit 1f985e3
Showing 1 changed file with 68 additions and 1 deletion.
69 changes: 68 additions & 1 deletion tests/LSP7DigitalAsset/LSP7DigitalAsset.behaviour.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1785,7 +1785,14 @@ export const shouldBehaveLikeLSP7 = (buildContext: () => Promise<LSP7TestContext

await expect(
context.lsp7.connect(caller).burn(ethers.constants.AddressZero, amount, '0x'),
).to.be.revertedWithCustomError(context.lsp7, 'LSP7CannotSendWithAddressZero');
)
.to.be.revertedWithCustomError(context.lsp7, 'LSP7AmountExceedsAuthorizedAmount')
.withArgs(
ethers.constants.AddressZero, // tokenOwner
0, // authorized amount
caller.address, // operator
amount, // amount
);
});
});

Expand Down Expand Up @@ -1943,6 +1950,22 @@ export const shouldBehaveLikeLSP7 = (buildContext: () => Promise<LSP7TestContext
expect(newAllowance).to.equal(0);
});

it('operator should have been removed from the list of operators for the token owner', async () => {
const operator = context.accounts.operator;
const amount = operatorAllowance;

const operatorsList = await context.lsp7.getOperatorsOf(context.accounts.owner.address);
expect(operatorsList).to.include(operator.address);

await context.lsp7.connect(operator).burn(context.accounts.owner.address, amount, '0x');

const updatedOperatorList = await context.lsp7.getOperatorsOf(
context.accounts.owner.address,
);
expect(updatedOperatorList.length).to.equal(operatorsList.length - 1);
expect(updatedOperatorList).to.not.include(operator.address);
});

it('token owner balance should have decreased', async () => {
const operator = context.accounts.operator;
const amount = operatorAllowance;
Expand Down Expand Up @@ -1982,6 +2005,20 @@ export const shouldBehaveLikeLSP7 = (buildContext: () => Promise<LSP7TestContext
'0x',
);
});

it('should have emitted a `RevokedOperator` event', async () => {
const operator = context.accounts.operator;
const amount = operatorAllowance;

const operatorsList = await context.lsp7.getOperatorsOf(context.accounts.owner.address);
expect(operatorsList).to.include(operator.address);

await expect(
context.lsp7.connect(operator).burn(context.accounts.owner.address, amount, '0x'),
)
.to.emit(context.lsp7, 'RevokedOperator')
.withArgs(operator.address, context.accounts.owner.address, '0x');
});
});

describe('when burning part of its allowance', () => {
Expand All @@ -2005,6 +2042,18 @@ export const shouldBehaveLikeLSP7 = (buildContext: () => Promise<LSP7TestContext
expect(newAllowance).to.equal(initialAllowance.sub(amount));
});

it('operator should still be in the list of operators for tokenOwner (and not have been removed)', async () => {
const amount = 10;
assert.isBelow(amount, operatorAllowance);

const operator = context.accounts.operator;

await context.lsp7.connect(operator).burn(context.accounts.owner.address, amount, '0x');

const operatorsList = await context.lsp7.getOperatorsOf(context.accounts.owner.address);
expect(operatorsList).to.include(operator.address);
});

it('token owner balance should have decreased', async () => {
const amount = 10;
assert.isBelow(amount, operatorAllowance);
Expand Down Expand Up @@ -2050,6 +2099,24 @@ export const shouldBehaveLikeLSP7 = (buildContext: () => Promise<LSP7TestContext
'0x',
);
});

it("should emit an `AuthorizedOperator` event with the updated operator's allowance", async () => {
const amount = 10;
assert.isBelow(amount, operatorAllowance);

const operator = context.accounts.operator;

await expect(
context.lsp7.connect(operator).burn(context.accounts.owner.address, amount, '0x'),
)
.to.emit(context.lsp7, 'AuthorizedOperator')
.withArgs(
operator.address,
context.accounts.owner.address,
operatorAllowance - amount,
'0x',
);
});
});

describe('when burning more than its allowance', () => {
Expand Down

0 comments on commit 1f985e3

Please sign in to comment.