Skip to content

Commit

Permalink
add InvalidPaymentMethod custom error
Browse files Browse the repository at this point in the history
  • Loading branch information
miquelcabot committed Dec 14, 2022
1 parent e795cc8 commit f643a96
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 7 deletions.
3 changes: 2 additions & 1 deletion contracts/SoulStore.sol
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.7;
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/security/Pausable.sol";

import "./libraries/Errors.sol";
import "./dex/PaymentGateway.sol";
import "./interfaces/ISoulboundIdentity.sol";
import "./interfaces/ISoulName.sol";
Expand Down Expand Up @@ -200,7 +201,7 @@ contract SoulStore is PaymentGateway, Pausable {
} else if (erc20token[paymentMethod]) {
return _convertFromStableCoin(paymentMethod, mintingPrice);
} else {
revert("INVALID_PAYMENT_METHOD");
revert InvalidPaymentMethod(paymentMethod);
}
}

Expand Down
3 changes: 2 additions & 1 deletion contracts/dex/PaymentGateway.sol
Expand Up @@ -6,6 +6,7 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";

import "../libraries/Errors.sol";
import "../interfaces/dex/IUniswapRouter.sol";

/// @title Pay using a Decentralized automated market maker (AMM) when needed
Expand Down Expand Up @@ -208,7 +209,7 @@ abstract contract PaymentGateway is Ownable {
swapAmout
);
} else {
revert("INVALID_PAYMENT_METHOD");
revert InvalidPaymentMethod(paymentMethod);
}
}

Expand Down
4 changes: 4 additions & 0 deletions contracts/libraries/Errors.sol
@@ -0,0 +1,4 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.7;

error InvalidPaymentMethod(address paymentMethod);
3 changes: 2 additions & 1 deletion contracts/tokens/MasaSBTSelfSovereign.sol
Expand Up @@ -5,6 +5,7 @@ import "@openzeppelin/contracts/utils/cryptography/draft-EIP712.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

import "../libraries/Errors.sol";
import "../interfaces/ISoulboundIdentity.sol";
import "../dex/PaymentGateway.sol";
import "./MasaSBT.sol";
Expand Down Expand Up @@ -124,7 +125,7 @@ abstract contract MasaSBTSelfSovereign is PaymentGateway, MasaSBT, EIP712 {
} else if (erc20token[paymentMethod]) {
return _convertFromStableCoin(paymentMethod, mintingPrice);
} else {
revert("INVALID_PAYMENT_METHOD");
revert InvalidPaymentMethod(paymentMethod);
}
}

Expand Down
19 changes: 19 additions & 0 deletions docs/SoulLinker.md
Expand Up @@ -834,3 +834,22 @@ event Unpaused(address account)



## Errors

### InvalidPaymentMethod

```solidity
error InvalidPaymentMethod(address paymentMethod)
```





#### Parameters

| Name | Type | Description |
|---|---|---|
| paymentMethod | address | undefined |


19 changes: 19 additions & 0 deletions docs/SoulStore.md
Expand Up @@ -647,3 +647,22 @@ event Unpaused(address account)



## Errors

### InvalidPaymentMethod

```solidity
error InvalidPaymentMethod(address paymentMethod)
```





#### Parameters

| Name | Type | Description |
|---|---|---|
| paymentMethod | address | undefined |


19 changes: 19 additions & 0 deletions docs/Soulbound2FA.md
Expand Up @@ -957,3 +957,22 @@ event Soulbound2FAMinted(uint256 tokenId, uint256 identityId, address authorityA



## Errors

### InvalidPaymentMethod

```solidity
error InvalidPaymentMethod(address paymentMethod)
```





#### Parameters

| Name | Type | Description |
|---|---|---|
| paymentMethod | address | undefined |


19 changes: 19 additions & 0 deletions docs/SoulboundCreditScore.md
Expand Up @@ -957,3 +957,22 @@ event SoulboundCreditScoreMinted(uint256 tokenId, uint256 identityId, address au



## Errors

### InvalidPaymentMethod

```solidity
error InvalidPaymentMethod(address paymentMethod)
```





#### Parameters

| Name | Type | Description |
|---|---|---|
| paymentMethod | address | undefined |


12 changes: 12 additions & 0 deletions docs/elin/contracts/security/ReentrancyGuard.md
@@ -0,0 +1,12 @@
# ReentrancyGuard







*Contract module that helps prevent reentrant calls to a function. Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier available, which can be applied to functions to make sure there are no nested (reentrant) calls to them. Note that because there is a single `nonReentrant` guard, functions marked as `nonReentrant` may not call one another. This can be worked around by making those functions `private`, and then adding `external` `nonReentrant` entry points to them. TIP: If you would like to learn more about reentrancy and alternative ways to protect against it, check out our blog post https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].*



19 changes: 19 additions & 0 deletions docs/tokens/MasaSBTSelfSovereign.md
Expand Up @@ -884,3 +884,22 @@ event RoleRevoked(bytes32 indexed role, address indexed account, address indexed



## Errors

### InvalidPaymentMethod

```solidity
error InvalidPaymentMethod(address paymentMethod)
```





#### Parameters

| Name | Type | Description |
|---|---|---|
| paymentMethod | address | undefined |


4 changes: 2 additions & 2 deletions test/SoulStore.test.ts
Expand Up @@ -821,7 +821,7 @@ describe("Soul Store", () => {
it("should fail to get purchase info for invalid payment method", async () => {
await expect(
soulStore.getPriceForMintingName(owner.address, SOUL_NAME, YEAR)
).to.be.rejectedWith("INVALID_PAYMENT_METHOD");
).to.be.rejectedWith("InvalidPaymentMethod");
});

it("we can't use an invalid payment method", async () => {
Expand All @@ -832,7 +832,7 @@ describe("Soul Store", () => {
YEAR,
ARWEAVE_LINK
)
).to.be.rejectedWith("INVALID_PAYMENT_METHOD");
).to.be.rejectedWith("InvalidPaymentMethod");
});
});
});
4 changes: 2 additions & 2 deletions test/SoulboundCreditScore.test.ts
Expand Up @@ -442,7 +442,7 @@ describe("Soulbound Credit Score", () => {
it("should fail to get minting info for invalid payment method", async () => {
await expect(
soulboundCreditScore.getMintingPrice(owner.address)
).to.be.rejectedWith("INVALID_PAYMENT_METHOD");
).to.be.rejectedWith("InvalidPaymentMethod");
});

it("we can't use an invalid payment method", async () => {
Expand All @@ -456,7 +456,7 @@ describe("Soulbound Credit Score", () => {
signatureDate,
signature
)
).to.be.rejectedWith("INVALID_PAYMENT_METHOD");
).to.be.rejectedWith("InvalidPaymentMethod");
});
});

Expand Down

0 comments on commit f643a96

Please sign in to comment.