UNPKG

@magiceden/magiceden-sdk

Version:

A TypeScript SDK for interacting with Magic Eden's API across multiple chains.

269 lines (268 loc) 14.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const ethereum_1 = require("../../mappers/nft/ethereum"); const chains_1 = require("../../types/chains"); const protocol_1 = require("../../types/protocol"); const shared_1 = require("../../types/services/nft/shared"); describe('EvmApiMappers V4', () => { describe('createLaunchpadRequest', () => { it('should correctly map create launchpad parameters for ERC721', () => { const params = { chain: chains_1.Blockchain.ETHEREUM, protocol: protocol_1.EvmProtocolType.ERC721, creator: '0x1234567890abcdef1234567890abcdef12345678', name: 'Test Collection', symbol: 'TEST', imageUrl: 'https://example.com/image.png', description: 'Test description', royaltyBps: 500, royaltyRecipients: [ { address: '0xabcdef1234567890abcdef1234567890abcdef12', share: 60 }, { address: '0x7890abcdef1234567890abcdef1234567890abcd', share: 40 }, ], payoutRecipient: '0x2345678901abcdef2345678901abcdef23456789', nftMetadataUrl: 'https://example.com/metadata.json', tokenImageUrl: 'https://example.com/token.png', mintStages: { stages: [ { kind: shared_1.MintStageKind.Public, price: { currency: { chain: chains_1.Blockchain.ETHEREUM, assetId: '0x0000000000000000000000000000000000000000' }, raw: '100000000000000000', }, startTime: '2023-01-01T00:00:00Z', endTime: '2023-01-02T00:00:00Z', walletLimit: 5, maxSupply: 100, }, ], maxSupply: 100, }, }; const result = ethereum_1.EvmApiMappers.v4.createLaunchpadRequest(params); // Verify the result is a valid V4CreateLaunchpadRequest expect(result).toBeDefined(); // Verify required EVM-specific properties expect(result.chain).toBe(chains_1.Blockchain.ETHEREUM); expect(result.protocol).toBe(protocol_1.EvmProtocolType.ERC721); expect(result.creator).toBe('0x1234567890abcdef1234567890abcdef12345678'); expect(result.social?.discordUrl).toBe('https://discord.com/test'); expect(result.social?.externalUrl).toBe('https://example.com'); expect(result.social?.twitterUsername).toBe('testuser'); expect(result.name).toBe('Test Collection'); expect(result.symbol).toBe('TEST'); expect(result.imageUrl).toBe('https://example.com/image.png'); expect(result.description).toBe('Test description'); expect(result.royaltyBps).toBe(500); expect(result.royaltyRecipients).toHaveLength(2); expect(result.payoutRecipient).toBe('0x2345678901abcdef2345678901abcdef23456789'); expect(result.nftMetadataUrl).toBe('https://example.com/metadata.json'); expect(result.tokenImageUrl).toBe('https://example.com/token.png'); // Verify mint stages expect(result.mintStages).toBeDefined(); expect(result.mintStages.stages).toHaveLength(1); expect(result.mintStages.stages[0].kind).toBe(shared_1.MintStageKind.Public); expect(result.mintStages.stages[0].price.currency).toBe('ETH'); expect(result.mintStages.stages[0].price.raw).toBe('100000000000000000'); expect(result.mintStages.maxSupply).toBe(100); }); it('should correctly map create launchpad parameters for ERC1155', () => { const params = { chain: chains_1.Blockchain.POLYGON, protocol: protocol_1.EvmProtocolType.ERC1155, creator: '0x1234567890abcdef1234567890abcdef12345678', name: 'Test Collection', symbol: 'TEST', imageUrl: 'https://example.com/image.png', description: 'Test description', royaltyBps: 500, royaltyRecipients: [{ address: '0xabcdef1234567890abcdef1234567890abcdef12', share: 100 }], payoutRecipient: '0x2345678901abcdef2345678901abcdef23456789', nftMetadataUrl: 'https://example.com/metadata.json', tokenImageUrl: 'https://example.com/token.png', mintStages: { stages: [ { kind: shared_1.MintStageKind.Public, price: { currency: { chain: chains_1.Blockchain.POLYGON, assetId: '0x0000000000000000000000000000000000000000' }, raw: '1000000000000000000', }, startTime: '2023-01-01T00:00:00Z', endTime: '2023-01-02T00:00:00Z', walletLimit: 10, maxSupply: 1000, }, ], maxSupply: 1000, }, }; const result = ethereum_1.EvmApiMappers.v4.createLaunchpadRequest(params); // Verify the result is a valid V4CreateLaunchpadRequest expect(result).toBeDefined(); // Verify required EVM-specific properties expect(result.chain).toBe(chains_1.Blockchain.POLYGON); expect(result.protocol).toBe(protocol_1.EvmProtocolType.ERC1155); expect(result.creator).toBe('0x1234567890abcdef1234567890abcdef12345678'); expect(result.name).toBe('Test Collection'); expect(result.symbol).toBe('TEST'); // Verify mint stages for ERC1155 expect(result.mintStages).toBeDefined(); expect(result.mintStages.stages[0].price.currency).toBe('MATIC'); expect(result.mintStages.maxSupply).toBe(1000); }); }); describe('updateLaunchpadRequest', () => { it('should correctly map update launchpad parameters', () => { const params = { chain: chains_1.Blockchain.ETHEREUM, protocol: protocol_1.EvmProtocolType.ERC721, collectionId: '0x3456789012abcdef3456789012abcdef34567890', owner: '0x4567890123abcdef4567890123abcdef45678901', name: 'Updated Collection', imageUrl: 'https://example.com/updated-image.png', description: 'Updated description', royaltyBps: 700, royaltyRecipients: [ { address: '0xabcdef1234567890abcdef1234567890abcdef12', share: 70 }, { address: '0x7890abcdef1234567890abcdef1234567890abcd', share: 30 }, ], payoutRecipient: '0x5678901234abcdef5678901234abcdef56789012', mintStages: { stages: [ { kind: shared_1.MintStageKind.Public, price: { currency: { chain: chains_1.Blockchain.ETHEREUM, assetId: '0x0000000000000000000000000000000000000000' }, raw: '200000000000000000', }, startTime: '2023-02-01T00:00:00Z', endTime: '2023-02-02T00:00:00Z', walletLimit: 3, maxSupply: 50, }, ], maxSupply: 50, }, }; const result = ethereum_1.EvmApiMappers.v4.updateLaunchpadRequest(params); // Verify the result is a valid V4UpdateLaunchpadRequest expect(result).toBeDefined(); // Verify chain and protocol expect(result.chain).toBe(chains_1.Blockchain.ETHEREUM); expect(result.protocol).toBe(protocol_1.EvmProtocolType.ERC721); // Verify collection and owner identifiers expect(result.collectionId).toBe('0x3456789012abcdef3456789012abcdef34567890'); expect(result.owner).toBe('0x4567890123abcdef4567890123abcdef45678901'); // Verify social media links expect(result.social?.discordUrl).toBe('https://discord.com/updated'); expect(result.social?.externalUrl).toBe('https://example.com/updated'); expect(result.social?.twitterUsername).toBe('updateduser'); // Verify metadata updates expect(result.name).toBe('Updated Collection'); expect(result.imageUrl).toBe('https://example.com/updated-image.png'); expect(result.description).toBe('Updated description'); // Verify royalty updates expect(result.royaltyBps).toBe(700); expect(result.royaltyRecipients).toHaveLength(2); expect(result.royaltyRecipients[0].address).toBe('0xabcdef1234567890abcdef1234567890abcdef12'); expect(result.royaltyRecipients[0].share).toBe(70); expect(result.royaltyRecipients[1].address).toBe('0x7890abcdef1234567890abcdef1234567890abcd'); expect(result.royaltyRecipients[1].share).toBe(30); // Verify payout recipient expect(result.payoutRecipient).toBe('0x5678901234abcdef5678901234abcdef56789012'); // Verify EVM-specific properties expect(result.message).toBe('Update collection message to sign'); expect(result.signature).toBe('0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890'); // Verify mint stages expect(result.mintStages).toBeDefined(); expect(result.mintStages.stages[0].price.currency).toBe('ETH'); expect(result.mintStages.maxSupply).toBe(50); }); it('should handle optional parameters for ERC1155', () => { const params = { chain: chains_1.Blockchain.POLYGON, protocol: protocol_1.EvmProtocolType.ERC1155, collectionId: '0x3456789012abcdef3456789012abcdef34567890', owner: '0x4567890123abcdef4567890123abcdef45678901', name: 'Updated ERC1155 Collection', tokenId: 1, }; const result = ethereum_1.EvmApiMappers.v4.updateLaunchpadRequest(params); // Verify required properties expect(result.chain).toBe(chains_1.Blockchain.POLYGON); expect(result.protocol).toBe(protocol_1.EvmProtocolType.ERC1155); expect(result.collectionId).toBe('0x3456789012abcdef3456789012abcdef34567890'); expect(result.owner).toBe('0x4567890123abcdef4567890123abcdef45678901'); expect(result.name).toBe('Updated ERC1155 Collection'); expect(result.tokenId).toBe(1); // Verify optional properties are undefined expect(result.description).toBeUndefined(); expect(result.royaltyBps).toBeUndefined(); expect(result.royaltyRecipients).toBeUndefined(); }); }); describe('mintRequest', () => { it('should correctly map mint parameters for ERC721', () => { const params = { chain: chains_1.Blockchain.ETHEREUM, protocol: protocol_1.EvmProtocolType.ERC721, collectionId: '0x3456789012abcdef3456789012abcdef34567890', nftAmount: 3, stageId: 'stage1', kind: shared_1.MintStageKind.Public, }; const result = ethereum_1.EvmApiMappers.v4.mintRequest('0x4567890123abcdef4567890123abcdef45678901', params); // Verify the result is a valid V4MintRequest expect(result).toBeDefined(); // Verify required EVM-specific properties expect(result.collectionId).toBe('0x3456789012abcdef3456789012abcdef34567890'); expect(result.wallet).toBe('0x4567890123abcdef4567890123abcdef45678901'); expect(result.nftAmount).toBe(3); expect(result.stageId).toBe('stage1'); expect(result.kind).toBe(shared_1.MintStageKind.Public); expect(result.protocol).toBe(protocol_1.EvmProtocolType.ERC721); expect(result.tokenId).toBeUndefined(); }); it('should correctly map mint parameters for ERC1155', () => { const params = { chain: chains_1.Blockchain.ETHEREUM, protocol: protocol_1.EvmProtocolType.ERC1155, collectionId: '0x3456789012abcdef3456789012abcdef34567890', nftAmount: 5, kind: shared_1.MintStageKind.Public, tokenId: 1, }; const result = ethereum_1.EvmApiMappers.v4.mintRequest('0x4567890123abcdef4567890123abcdef45678901', params); // Verify required properties expect(result.collectionId).toBe('0x3456789012abcdef3456789012abcdef34567890'); expect(result.wallet).toBe('0x4567890123abcdef4567890123abcdef45678901'); expect(result.nftAmount).toBe(5); expect(result.kind).toBe(shared_1.MintStageKind.Public); expect(result.protocol).toBe(protocol_1.EvmProtocolType.ERC1155); expect(result.tokenId).toBe(1); // Verify optional properties are undefined expect(result.stageId).toBeUndefined(); }); it('should handle optional parameters', () => { const params = { chain: chains_1.Blockchain.ETHEREUM, protocol: protocol_1.EvmProtocolType.ERC721, collectionId: '0x3456789012abcdef3456789012abcdef34567890', nftAmount: 1, kind: shared_1.MintStageKind.Public, }; const result = ethereum_1.EvmApiMappers.v4.mintRequest('0x4567890123abcdef4567890123abcdef45678901', params); // Verify required properties expect(result.collectionId).toBe('0x3456789012abcdef3456789012abcdef34567890'); expect(result.wallet).toBe('0x4567890123abcdef4567890123abcdef45678901'); expect(result.nftAmount).toBe(1); expect(result.kind).toBe(shared_1.MintStageKind.Public); expect(result.protocol).toBe(protocol_1.EvmProtocolType.ERC721); // Verify optional properties are undefined expect(result.stageId).toBeUndefined(); expect(result.tokenId).toBeUndefined(); }); }); });