diff --git a/packages/core/test/creation.test.js b/packages/core/test/creation.test.js index a67c99ff..af60e13f 100644 --- a/packages/core/test/creation.test.js +++ b/packages/core/test/creation.test.js @@ -10,7 +10,6 @@ const { connect, Near } = require("@near-js/wallet-account"); const keypom = require('../lib'); const { Account } = require('@near-js/accounts'); const { parseNearAmount } = require('@near-js/utils'); -const { getKeyTotalSupply } = require('../lib/lib/views'); const { execute, initKeypom, @@ -26,8 +25,8 @@ const { addToBalance } = keypom; -const NETWORK_ID = 'mainnet'; -const funderAccountId = 'keypom.near'; +const NETWORK_ID = 'testnet'; +const funderAccountId = 'benjiman.testnet'; const viewAccountId = NETWORK_ID == 'mainnet' ? 'near' : 'testnet'; /// all tests @@ -38,6 +37,7 @@ test('init', async (t) => { const credentialsPath = path.join(homedir, CREDENTIALS_DIR); let keyStore = new UnencryptedFileSystemKeyStore(credentialsPath); + let nearConfig = { networkId: NETWORK_ID, keyStore: keyStore, @@ -46,277 +46,256 @@ test('init', async (t) => { helperUrl: `https://helper.${NETWORK_ID}.near.org`, explorerUrl: `https://explorer.${NETWORK_ID}.near.org`, }; + let near = new Near(nearConfig); - - + fundingAccount = new Account(near.connection, funderAccountId); + await initKeypom({ near }); + + t.true(true); +}); + +test('token drop', async (t) => { + const wallets = ['mynearwallet', 'herewallet']; + const dropName = 'My Cool Drop Name'; + const depositPerUseNEAR = 1; + const numKeys = 1; + const usesPerKey = 1; + const masterKey = 'MASTER_KEY'; + + const {dropId} = await createDrop({ + account: fundingAccount, + numKeys: 0, + config: { + usesPerKey, + usage: { + autoDeleteDrop: true, + autoWithdraw: true, + } + }, + metadata: JSON.stringify({ + dropName, + wallets + }), + depositPerUseNEAR, + }); + + let allSecretKeys = []; + // Loop through in intervals of 50 until numKeys is reached + let keysAdded = 0; + while (keysAdded < numKeys) { + const keysToAdd = Math.min(50, numKeys - keysAdded); + const {secretKeys, publicKeys} = await generateKeys({ + numKeys: keysToAdd, + rootEntropy: `${masterKey}-${dropId}`, + autoMetaNonceStart: keysAdded + }); + await addKeys({ + account: fundingAccount, + dropId, + publicKeys + }); + keysAdded += keysToAdd; + + allSecretKeys = allSecretKeys.concat(secretKeys); + } + + const {contractId} = getEnv(); + + const baseUrl = NETWORK_ID === 'testnet' ? 'https://testnet.keypom-airfoil.pages.dev/claim' : 'https://keypom.xyz/claim'; - const dropSupply = await getKeyTotalSupply(); - console.log('dropSupply: ', dropSupply) + const secretKeysStripped = allSecretKeys.map((sk) => `${baseUrl}/${contractId}/${sk.split(':')[1]}`); + + let stringToWrite = ''; + // Loop through each secret key + var i = 0; + for (const sk of secretKeysStripped) { + stringToWrite += sk + '\n'; + i++; + } + + await writeFile(path.resolve(__dirname, 'token_links.json'), stringToWrite); - const fundingAccount = new Account(near.connection, funderAccountId); - const {keys} = await createDrop({ + t.true(true); +}); + +test('NFT drop', async (t) => { + const wallets = ["mynearwallet", "herewallet"]; + const dropName = "My Cool Drop Name"; + const depositPerUseNEAR = 0.1; + const numKeys = 50; + const usesPerKey = 1; + const masterKey = "MASTER_KEY"; + + const nftTitle = "Moon NFT!"; + const nftDescription = "A cool NFT for the best dog in the world."; + const nftMediaIPFSHash = "bafybeibwhlfvlytmttpcofahkukuzh24ckcamklia3vimzd4vkgnydy7nq"; + + const {dropId} = await createDrop({ account: fundingAccount, - numKeys: 1, - depositPerUseNEAR: 1 + numKeys: 0, + metadata: JSON.stringify({ + dropName, + wallets + }), + config: { + usesPerKey + }, + depositPerUseNEAR, + fcData: { + methods: [[ + { + receiverId: `nft-v2.keypom.${viewAccountId}`, + methodName: "nft_mint", + args: "", + dropIdField: "mint_id", + accountIdField: "receiver_id", + attachedDeposit: parseNearAmount("0.008") + } + ]] + } }) - console.log('keys: ', keys) - t.true(true); + let allSecretKeys = []; + // Loop through in intervals of 50 until numKeys is reached + let keysAdded = 0; + while (keysAdded < numKeys) { + const keysToAdd = Math.min(50, numKeys - keysAdded); + const {secretKeys, publicKeys} = await generateKeys({ + numKeys: keysToAdd, + rootEntropy: `${masterKey}-${dropId}`, + autoMetaNonceStart: keysAdded + }) + await addKeys({ + account: fundingAccount, + dropId, + publicKeys + }) + keysAdded += keysToAdd; + + allSecretKeys = allSecretKeys.concat(secretKeys); + } + + await keypom.createNFTSeries({ + account: fundingAccount, + dropId, + metadata: { + title: nftTitle, + description: nftDescription, + media: nftMediaIPFSHash + } + }); + + const {contractId} = getEnv(); + + const baseUrl = NETWORK_ID === "testnet" ? `https://testnet.keypom-airfoil.pages.dev/claim` : `https://keypom.xyz/claim` + + const secretKeysStripped = allSecretKeys.map((sk) => `${baseUrl}/${contractId}#${sk.split(":")[1]}`) + + let stringToWrite = "" + // Loop through each secret key + var i = 0; + for (const sk of secretKeysStripped) { + stringToWrite += sk + "\n"; + i++; + } + + await writeFile(path.resolve(__dirname, `nft_links.json`), stringToWrite); + + t.true(true); }); -// test('token drop', async (t) => { -// const wallets = ['mynearwallet', 'herewallet']; -// const dropName = 'My Cool Drop Name'; -// const depositPerUseNEAR = 1; -// const numKeys = 1; -// const usesPerKey = 1; -// const masterKey = 'MASTER_KEY'; - -// const {dropId} = await createDrop({ -// account: fundingAccount, -// numKeys: 0, -// config: { -// usesPerKey, -// usage: { -// autoDeleteDrop: true, -// autoWithdraw: true, -// } -// }, -// metadata: JSON.stringify({ -// dropName, -// wallets -// }), -// fcData: { -// methods: [[ -// { -// receiverId: NETWORK_ID === 'testnet' ? 'v1.social08.testnet' : 'social.near', -// methodName: "storage_deposit", -// args: JSON.stringify({}), -// accountIdField: "account_id", -// attachedDeposit: parseNearAmount("0.1") -// } -// ]] -// }, -// depositPerUseNEAR, -// }); - -// let allSecretKeys = []; -// // Loop through in intervals of 50 until numKeys is reached -// let keysAdded = 0; -// while (keysAdded < numKeys) { -// const keysToAdd = Math.min(50, numKeys - keysAdded); -// const {secretKeys, publicKeys} = await generateKeys({ -// numKeys: keysToAdd, -// rootEntropy: `${masterKey}-${dropId}`, -// autoMetaNonceStart: keysAdded -// }); -// await addKeys({ -// account: fundingAccount, -// dropId, -// publicKeys -// }); -// keysAdded += keysToAdd; - -// allSecretKeys = allSecretKeys.concat(secretKeys); -// } - -// const {contractId} = getEnv(); - -// const baseUrl = NETWORK_ID === 'testnet' ? 'https://testnet.mynearwallet.com/linkdrop' : 'https://localhost:1234/linkdrop'; - -// const secretKeysStripped = allSecretKeys.map((sk) => `${baseUrl}/${contractId}/${sk.split(':')[1]}`); - -// let stringToWrite = ''; -// // Loop through each secret key -// var i = 0; -// for (const sk of secretKeysStripped) { -// stringToWrite += sk + '\n'; -// i++; -// } - -// await writeFile(path.resolve(__dirname, 'token_links.json'), stringToWrite); - -// t.true(true); -// }); - -// test('NFT drop', async (t) => { -// const wallets = ["mynearwallet", "herewallet"]; -// const dropName = "My Cool Drop Name"; -// const depositPerUseNEAR = 0.1; -// const numKeys = 50; -// const usesPerKey = 1; -// const masterKey = "MASTER_KEY"; - -// const nftTitle = "Moon NFT!"; -// const nftDescription = "A cool NFT for the best dog in the world."; -// const nftMediaIPFSHash = "bafybeibwhlfvlytmttpcofahkukuzh24ckcamklia3vimzd4vkgnydy7nq"; - -// const {dropId} = await createDrop({ -// account: fundingAccount, -// numKeys: 0, -// metadata: JSON.stringify({ -// dropName, -// wallets -// }), -// config: { -// usesPerKey -// }, -// depositPerUseNEAR, -// fcData: { -// methods: [[ -// { -// receiverId: `nft-v2.keypom.${viewAccountId}`, -// methodName: "nft_mint", -// args: "", -// dropIdField: "mint_id", -// accountIdField: "receiver_id", -// attachedDeposit: parseNearAmount("0.008") -// } -// ]] -// } -// }) - -// let allSecretKeys = []; -// // Loop through in intervals of 50 until numKeys is reached -// let keysAdded = 0; -// while (keysAdded < numKeys) { -// const keysToAdd = Math.min(50, numKeys - keysAdded); -// const {secretKeys, publicKeys} = await generateKeys({ -// numKeys: keysToAdd, -// rootEntropy: `${masterKey}-${dropId}`, -// autoMetaNonceStart: keysAdded -// }) -// await addKeys({ -// account: fundingAccount, -// dropId, -// publicKeys -// }) -// keysAdded += keysToAdd; - -// allSecretKeys = allSecretKeys.concat(secretKeys); -// } - -// await keypom.createNFTSeries({ -// account: fundingAccount, -// dropId, -// metadata: { -// title: nftTitle, -// description: nftDescription, -// media: nftMediaIPFSHash -// } -// }); - -// const {contractId} = getEnv(); - -// const baseUrl = NETWORK_ID === "testnet" ? `https://testnet.keypom-airfoil.pages.dev/claim` : `https://keypom.xyz/claim` - -// const secretKeysStripped = allSecretKeys.map((sk) => `${baseUrl}/${contractId}#${sk.split(":")[1]}`) - -// let stringToWrite = "" -// // Loop through each secret key -// var i = 0; -// for (const sk of secretKeysStripped) { -// stringToWrite += sk + "\n"; -// i++; -// } - -// await writeFile(path.resolve(__dirname, `nft_links.json`), stringToWrite); - -// t.true(true); -// }); - -// test('Ticket drops', async (t) => { -// const wallets = ["mynearwallet", "herewallet"]; -// const dropName = "My Cool Drop Name"; -// const depositPerUseNEAR = 0.1; -// const numKeys = 50; -// const usesPerKey = 3; -// const masterKey = "MASTER_KEY"; +test('Ticket drops', async (t) => { + const wallets = ["mynearwallet", "herewallet"]; + const dropName = "My Cool Drop Name"; + const depositPerUseNEAR = 0.1; + const numKeys = 50; + const usesPerKey = 3; + const masterKey = "MASTER_KEY"; -// const eventPassword = "event-password"; -// const nftTitle = "Moon NFT!"; -// const nftDescription = "A cool NFT for the best dog in the world."; -// const nftMediaIPFSHash = "bafybeibwhlfvlytmttpcofahkukuzh24ckcamklia3vimzd4vkgnydy7nq"; - -// const {dropId} = await createDrop({ -// account: fundingAccount, -// numKeys: 0, -// metadata: JSON.stringify({ -// dropName, -// wallets -// }), -// config: { -// usesPerKey -// }, -// depositPerUseNEAR, -// fcData: { -// methods: [ -// null, -// null, -// [ -// { -// receiverId: `nft-v2.keypom.${viewAccountId}`, -// methodName: "nft_mint", -// args: "", -// dropIdField: "mint_id", -// accountIdField: "receiver_id", -// attachedDeposit: parseNearAmount("0.008") -// } -// ] -// ] -// } -// }) - -// let allSecretKeys = []; -// // Loop through in intervals of 50 until numKeys is reached -// let keysAdded = 0; -// while (keysAdded < numKeys) { -// const keysToAdd = Math.min(50, numKeys - keysAdded); -// const {secretKeys, publicKeys} = await generateKeys({ -// numKeys: keysToAdd, -// rootEntropy: `${masterKey}-${dropId}`, -// autoMetaNonceStart: keysAdded -// }) -// await addKeys({ -// account: fundingAccount, -// dropId, -// publicKeys, -// basePassword: eventPassword, -// passwordProtectedUses: [2] -// }) -// keysAdded += keysToAdd; - -// allSecretKeys = allSecretKeys.concat(secretKeys); -// } - -// await keypom.createNFTSeries({ -// account: fundingAccount, -// dropId, -// metadata: { -// title: nftTitle, -// description: nftDescription, -// media: nftMediaIPFSHash -// } -// }); - -// const {contractId} = getEnv(); - -// const baseUrl = NETWORK_ID === "testnet" ? `https://testnet.keypom-airfoil.pages.dev/claim` : `https://keypom.xyz/claim` - -// const secretKeysStripped = allSecretKeys.map((sk) => `${baseUrl}/${contractId}#${sk.split(":")[1]}`) - -// let stringToWrite = "" -// // Loop through each secret key -// var i = 0; -// for (const sk of secretKeysStripped) { -// stringToWrite += sk + "\n"; -// i++; -// } - -// await writeFile(path.resolve(__dirname, `ticket_links.json`), stringToWrite); - -// t.true(true); -// }); \ No newline at end of file + const eventPassword = "event-password"; + const nftTitle = "Moon NFT!"; + const nftDescription = "A cool NFT for the best dog in the world."; + const nftMediaIPFSHash = "bafybeibwhlfvlytmttpcofahkukuzh24ckcamklia3vimzd4vkgnydy7nq"; + + const {dropId} = await createDrop({ + account: fundingAccount, + numKeys: 0, + metadata: JSON.stringify({ + dropName, + wallets + }), + config: { + usesPerKey + }, + depositPerUseNEAR, + fcData: { + methods: [ + null, + null, + [ + { + receiverId: `nft-v2.keypom.${viewAccountId}`, + methodName: "nft_mint", + args: "", + dropIdField: "mint_id", + accountIdField: "receiver_id", + attachedDeposit: parseNearAmount("0.008") + } + ] + ] + } + }) + + let allSecretKeys = []; + // Loop through in intervals of 50 until numKeys is reached + let keysAdded = 0; + while (keysAdded < numKeys) { + const keysToAdd = Math.min(50, numKeys - keysAdded); + const {secretKeys, publicKeys} = await generateKeys({ + numKeys: keysToAdd, + rootEntropy: `${masterKey}-${dropId}`, + autoMetaNonceStart: keysAdded + }) + await addKeys({ + account: fundingAccount, + dropId, + publicKeys, + basePassword: eventPassword, + passwordProtectedUses: [2] + }) + keysAdded += keysToAdd; + + allSecretKeys = allSecretKeys.concat(secretKeys); + } + + await keypom.createNFTSeries({ + account: fundingAccount, + dropId, + metadata: { + title: nftTitle, + description: nftDescription, + media: nftMediaIPFSHash + } + }); + + const {contractId} = getEnv(); + + const baseUrl = NETWORK_ID === "testnet" ? `https://testnet.keypom-airfoil.pages.dev/claim` : `https://keypom.xyz/claim` + + const secretKeysStripped = allSecretKeys.map((sk) => `${baseUrl}/${contractId}#${sk.split(":")[1]}`) + + let stringToWrite = "" + // Loop through each secret key + var i = 0; + for (const sk of secretKeysStripped) { + stringToWrite += sk + "\n"; + i++; + } + + await writeFile(path.resolve(__dirname, `ticket_links.json`), stringToWrite); + + t.true(true); +}); \ No newline at end of file