Skip to content

Commit

Permalink
feat: throw error when nft minter pk or contract addr is not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
luisantoniocrag committed Nov 4, 2024
1 parent e2937dd commit 49c8a23
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
21 changes: 13 additions & 8 deletions src/handlers/generate-erc721-permit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,22 @@ export async function generateErc721PermitSignature(
_repositoryName = contextOrPermitPayload.repositoryName;
_userId = contextOrPermitPayload.userId;
} else {
const { NFT_MINTER_PRIVATE_KEY = "", NFT_CONTRACT_ADDRESS = "" } = contextOrPermitPayload.env;
const { NFT_MINTER_PRIVATE_KEY, NFT_CONTRACT_ADDRESS } = contextOrPermitPayload.env;

_logger = contextOrPermitPayload.logger;

if (!NFT_MINTER_PRIVATE_KEY) {
_logger.error("NFT minter private key is not defined");
throw new Error("NFT minter private key is not defined");
}

if (!NFT_CONTRACT_ADDRESS) {
_logger.error("NFT contract address is not defined");
throw new Error("NFT contract address is not defined");
}

const { evmNetworkId } = contextOrPermitPayload.config;
const adapters = contextOrPermitPayload.adapters;
_logger = contextOrPermitPayload.logger;
_nftContractAddress = NFT_CONTRACT_ADDRESS;
_evmNetworkId = evmNetworkId;
_nftMinterPrivateKey = NFT_MINTER_PRIVATE_KEY;
Expand Down Expand Up @@ -103,12 +114,6 @@ export async function generateErc721PermitSignature(
throw new Error("Provider is not defined");
}

if (!_nftContractAddress) {
const errorMessage = "NFT contract address is not defined";
_logger.error(errorMessage);
throw new Error(errorMessage);
}

let adminWallet;

try {
Expand Down
2 changes: 1 addition & 1 deletion tests/generate-erc721-permit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ describe("generateErc721PermitSignature", () => {

it("should throw an error if NFT minter private key is not defined", async () => {
delete process.env.NFT_MINTER_PRIVATE_KEY;
await expect(generateErc721PermitSignature(context, "123", "contribution")).rejects.toThrow("Failed to" + " instantiate wallet");
await expect(generateErc721PermitSignature(context, "123", "contribution")).rejects.toThrow("NFT minter" + " private key" + " is not defined");
expect(context.logger.error).toHaveBeenCalled();
});

Expand Down

0 comments on commit 49c8a23

Please sign in to comment.