Skip to content

Commit

Permalink
Apply PR fix 976 + Merge branch 'develop' into refactor/lsp7-with-erc…
Browse files Browse the repository at this point in the history
…725-v8
  • Loading branch information
CJ42 committed Oct 18, 2024
2 parents f6d132a + 62949a9 commit abf03cc
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Since the `@lukso/lsp-smart-contracts` is an Open Source project, we welcome con
- report bug and issues.
- introduce new features or bug fixes.

Any non-trivial code contribution **must be first discussed with the maintainers and the developer community in an [issue](https://github.com/lukso-network/lsp-smart-contracts/issues/new/choose)**. Only very minor changes are accepted without prior discussion.

## **Clone project**

Our project uses submodules, we recommend you to clone our repository using the following command:
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ The following audits and formal verification were conducted. All high-level issu
- MiloTruck, 2023-11-31, Final Result: [MiloTruck_audit_2023_11_31.pdf](./audits/MiloTruck_audit_2023_11_31.pdf)
- MiloTruck, 2024-01-24, Final Result: [MiloTruck_audit_2024_01_24.pdf](./audits/MiloTruck_audit_2024_01_24.pdf)

## Contribute

The implementation contracts of the [LSPs](https://github.com/lukso-network/LIPs) exist thanks to their contributors. There are many ways you can participate and help build high quality software. Check out the [contribution guidelines](./CONTRIBUTING.md)!

## Contributors ✨

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2207,6 +2207,80 @@ export const shouldBehaveLikeLSP7 = (buildContext: () => Promise<LSP7TestContext
});
});

describe('when transferring 0 as amount', () => {
describe('when the caller is the tokenOwner', () => {
it('should succeed', async () => {
const tokenOwner = context.accounts.owner.address;
const recipient = context.accounts.anyone.address;
const amount = 0;

await expect(
context.lsp7
.connect(context.accounts.owner)
.transfer(tokenOwner, recipient, amount, true, '0x'),
)
.to.emit(context.lsp7, 'Transfer')
.withArgs(tokenOwner, tokenOwner, recipient, amount, true, '0x');
});
});

describe('when the caller is the operator', () => {
describe("when the caller doesn't have an authorized amount", () => {
it('should revert', async () => {
const operator = context.accounts.operator.address;
const tokenOwner = context.accounts.owner.address;
const recipient = context.accounts.anyone.address;
const amount = 0;

await expect(
context.lsp7
.connect(context.accounts.operator)
.transfer(tokenOwner, recipient, amount, true, '0x'),
)
.to.be.revertedWithCustomError(context.lsp7, 'LSP7AmountExceedsAuthorizedAmount')
.withArgs(tokenOwner, 0, operator, amount);
});
});
describe('when the caller have an authorized amount', () => {
it('should succeed', async () => {
const operator = context.accounts.operator.address;
const tokenOwner = context.accounts.owner.address;
const recipient = context.accounts.anyone.address;
const amountAuthorized = 100;
const amount = 0;

// pre-conditions
await context.lsp7
.connect(context.accounts.owner)
.authorizeOperator(operator, amountAuthorized, '0x');
expect(await context.lsp7.authorizedAmountFor(operator, tokenOwner)).to.equal(
amountAuthorized,
);

await expect(
context.lsp7
.connect(context.accounts.operator)
.transfer(tokenOwner, recipient, amount, true, '0x'),
)
.to.emit(context.lsp7, 'Transfer')
.withArgs(operator, tokenOwner, recipient, amount, true, '0x');
});
});
});

describe('when making a call with sending value', () => {
it('should revert', async () => {
const amountSent = 200;
await expect(
context.accounts.anyone.sendTransaction({
to: await context.lsp7.getAddress(),
value: amountSent,
}),
).to.be.revertedWithCustomError(context.lsp7, 'LSP7TokenContractCannotHoldValue');
});
});
});

describe('batchCalls', () => {
describe('when using one function', () => {
describe('using `mint(...)`', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/lsp7-contracts/contracts/LSP7DigitalAsset.sol
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ abstract contract LSP7DigitalAsset is
operator
];

if (amountToSpend > authorizedAmount) {
if (authorizedAmount == 0 || amountToSpend > authorizedAmount) {
revert LSP7AmountExceedsAuthorizedAmount(
tokenOwner,
authorizedAmount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ abstract contract LSP7DigitalAssetInitAbstract is
operator
];

if (amountToSpend > authorizedAmount) {
if (authorizedAmount == 0 || amountToSpend > authorizedAmount) {
revert LSP7AmountExceedsAuthorizedAmount(
tokenOwner,
authorizedAmount,
Expand Down

0 comments on commit abf03cc

Please sign in to comment.