How to use txn method in wpt

Best JavaScript code snippet using wpt

transaction.ts

Source:transaction.ts Github

copy

Full Screen

1import { API, graphqlOperation } from 'aws-amplify';2import { loader } from 'graphql.macro';3import * as _ from 'lodash';4import { configuration } from '../config'5const stage: string = process.env.REACT_APP_STAGE != undefined ? process.env.REACT_APP_STAGE : "dev"6const algosdk = require('algosdk');7declare var AlgoSigner: any;8export const algorandGetAccountInfo = async (account: any) => {9 const query = loader('../graphql/algorandGetAccountInfo.gql');10 try {11 const result: any = await API.graphql(graphqlOperation(query, { account: account }));12 // console.log('algorandGetAccountInfo with result: ', result);13 return result.data.algorandGetAccountInfo14 } catch (error) {15 throw error16 }17}18export const algorandGetTxParams = async () => {19 const query = loader('../graphql/algorandGetTxParams.gql');20 try {21 const result: any = await API.graphql(graphqlOperation(query));22 // console.log('algorandGetTxParams with result: ', result);23 return result.data.algorandGetTxParams24 } catch (error) {25 throw error26 }27}28export const algorandGetTxParamsWithDelay = async () => {29 const query = loader('../graphql/algorandGetTxParamsWithDelay.gql');30 try {31 const result: any = await API.graphql(graphqlOperation(query));32 // console.log('algorandGetTxParamsWithDelay with result: ', result);33 return result.data.algorandGetTxParamsWithDelay34 } catch (error) {35 throw error36 }37}38export function createMultiSigAddress(payload: { seller: string, buyer: string, arbitrator: string, backup: string }): string {39 console.log("createMultiSigAddress payload: ", payload)40 const mparams = {41 version: 1,42 threshold: 2,43 addrs: [44 payload.seller,45 payload.buyer,46 payload.arbitrator,47 payload.backup48 ],49 };50 try {51 return algosdk.multisigAddress(mparams);;52 }53 catch (error) {54 console.log(error);55 return "error createMultiSigAddress";56 }57}58export function signTransactionsAcceptAndPayMnemonicAlgo(multiSigAddress: any, params: any, mnemonicSecretKey: any, toPayAlgo: any, buyer: any, assetId: any, feeCommissionUC: any, commissionUCAddress: any) {59 try {60 const txnOptin = algosdk.makeAssetTransferTxnWithSuggestedParams(buyer, buyer, undefined, undefined, 0, undefined, assetId, params)61 // console.log("signTransactionsAcceptAndPayMnemonicAlgo txnOptin: ", txnOptin)62 const txnPayment = algosdk.makePaymentTxnWithSuggestedParams(buyer, multiSigAddress, toPayAlgo * 1000000, undefined, undefined, params);63 // console.log("signTransactionsAcceptAndPayMnemonicAlgo txnPayment: ", txnPayment)64 const txnPaymentCommission = algosdk.makePaymentTxnWithSuggestedParams(buyer, commissionUCAddress, feeCommissionUC * 1000000, undefined, undefined, params);65 // console.log("signTransactionsAcceptAndPayMnemonicAlgo txnPaymentCommission: ", txnPaymentCommission)66 let gid = algosdk.assignGroupID([txnOptin, txnPayment, txnPaymentCommission]);67 const secret_key = algosdk.mnemonicToSecretKey(mnemonicSecretKey);68 let signedOptinTxn = algosdk.signTransaction(txnOptin, secret_key.sk)69 signedOptinTxn.blob = signedOptinTxn.blob.toString()70 let signedPaymentTxn = algosdk.signTransaction(txnPayment, secret_key.sk)71 signedPaymentTxn.blob = signedPaymentTxn.blob.toString()72 let signedPaymentCommissionTxn = algosdk.signTransaction(txnPaymentCommission, secret_key.sk)73 signedPaymentCommissionTxn.blob = signedPaymentCommissionTxn.blob.toString()74 return [signedOptinTxn, signedPaymentTxn, signedPaymentCommissionTxn]75 } catch (error) {76 console.log("signTransactionsAcceptAndPayMnemonicAlgo API error: ", error)77 throw error78 }79}80// export function signTransactionsAcceptAndPayMnemonicPaid(params: any, mnemonicSecretKey: any, buyer: any, assetId: any) {81// try {82// const txnOptin = algosdk.makeAssetTransferTxnWithSuggestedParams(buyer, buyer, undefined, undefined, 0, undefined, assetId, params)83// console.log("signTransactionsAcceptAndPayPaid txnOptin: ", txnOptin)84// const secret_key = algosdk.mnemonicToSecretKey(mnemonicSecretKey);85// let signedOptinTxn = algosdk.signTransaction(txnOptin, secret_key.sk)86// signedOptinTxn.blob = signedOptinTxn.blob.toString()87// return [signedOptinTxn]88// } catch (error) {89// console.log("signTransactionsAcceptAndPayPaid API error: ", error)90// throw error91// }92// }93export function signTransactionsAcceptAndPayMnemonicAssetOptin(multiSigAddress: any, params: any, mnemonicSecretKey: any, toPayAlgo: any, toPayAssetCurrency: any, buyerAddress: any, assetIdSow: any, assetCurrencyIndex: any, mparams: any, feeCommissionUC: any, commissionUCAddress: any) {94 try {95 const txnPaymentAlgo = algosdk.makePaymentTxnWithSuggestedParams(buyerAddress, multiSigAddress, toPayAlgo * 1000000, undefined, undefined, params);96 // console.log("signTransactionsAcceptAndPayMnemonicAssetOptin txnPayment: ", txnPaymentAlgo)97 const txnOptinAssetCurrencyMsig = algosdk.makeAssetTransferTxnWithSuggestedParams(multiSigAddress, multiSigAddress, undefined, undefined, 0, undefined, assetCurrencyIndex, params)98 // console.log("signTransactionsAcceptAndPayMnemonicAssetOptin txnOptinAssetCurrencyMsig: ", txnOptinAssetCurrencyMsig)99 const txnOptinAssetSowBuyer = algosdk.makeAssetTransferTxnWithSuggestedParams(buyerAddress, buyerAddress, undefined, undefined, 0, undefined, assetIdSow, params)100 // console.log("signTransactionsAcceptAndPayMnemonicAssetOptin txnOptinAssetSowBuyer: ", txnOptinAssetSowBuyer)101 const txnPaymentAssetCurrency = algosdk.makeAssetTransferTxnWithSuggestedParams(buyerAddress, multiSigAddress, undefined, undefined, toPayAssetCurrency * 100, undefined, assetCurrencyIndex, params)102 // console.log("signTransactionsAcceptAndPayMnemonicAssetOptin txnPaymentAssetCurrency: ", txnPaymentAssetCurrency)103 const txnPaymentCommission = algosdk.makeAssetTransferTxnWithSuggestedParams(buyerAddress, commissionUCAddress, undefined, undefined, feeCommissionUC * 100, undefined, assetCurrencyIndex, params)104 // console.log("signTransactionsAcceptAndPayMnemonicAssetOptin txnPaymentCommission: ", txnPaymentCommission)105 let gid = algosdk.assignGroupID([txnPaymentAlgo, txnOptinAssetCurrencyMsig, txnOptinAssetSowBuyer, txnPaymentAssetCurrency, txnPaymentCommission]);106 const secret_key = algosdk.mnemonicToSecretKey(mnemonicSecretKey);107 let signedTxnPaymentAlgo = algosdk.signTransaction(txnPaymentAlgo, secret_key.sk)108 signedTxnPaymentAlgo.blob = signedTxnPaymentAlgo.blob.toString()109 let signedTxnOptinAssetCurrencyMsig = algosdk.signMultisigTransaction(txnOptinAssetCurrencyMsig, mparams, secret_key.sk)110 signedTxnOptinAssetCurrencyMsig.blob = signedTxnOptinAssetCurrencyMsig.blob.toString()111 let signedTxnOptinAssetSowBuyer = algosdk.signTransaction(txnOptinAssetSowBuyer, secret_key.sk)112 signedTxnOptinAssetSowBuyer.blob = signedTxnOptinAssetSowBuyer.blob.toString()113 let signedTxnPaymentAssetCurrency = algosdk.signTransaction(txnPaymentAssetCurrency, secret_key.sk)114 signedTxnPaymentAssetCurrency.blob = signedTxnPaymentAssetCurrency.blob.toString()115 let signedTxnPaymentCommission = algosdk.signTransaction(txnPaymentCommission, secret_key.sk)116 signedTxnPaymentCommission.blob = signedTxnPaymentCommission.blob.toString()117 return [signedTxnPaymentAlgo, signedTxnOptinAssetCurrencyMsig, signedTxnOptinAssetSowBuyer, signedTxnPaymentAssetCurrency, signedTxnPaymentCommission]118 } catch (error) {119 console.log("signTransactionsAcceptAndPayMnemonicAssetOptin API error: ", error)120 throw error121 }122}123export function signTransactionsAcceptAndPayMnemonicAsset(multiSigAddress: any, params: any, mnemonicSecretKey: any, toPayAlgo: any, toPayAssetCurrency: any, buyerAddress: any, assetIdSow: any, assetCurrencyIndex: any, feeCommissionUC: any, commissionUCAddress: any) {124 try {125 const txnPaymentAlgo = algosdk.makePaymentTxnWithSuggestedParams(buyerAddress, multiSigAddress, toPayAlgo, undefined, undefined, params);126 // console.log("signTransactionsAcceptAndPayMnemonicAsset txnPayment: ", txnPaymentAlgo)127 const txnOptinAssetSowBuyer = algosdk.makeAssetTransferTxnWithSuggestedParams(buyerAddress, buyerAddress, undefined, undefined, 0, undefined, assetIdSow, params)128 // console.log("signTransactionsAcceptAndPayMnemonicAsset txnOptinAssetSowBuyer: ", txnOptinAssetSowBuyer)129 const txnPaymentAssetCurrency = algosdk.makeAssetTransferTxnWithSuggestedParams(buyerAddress, multiSigAddress, undefined, undefined, toPayAssetCurrency * 100, undefined, assetCurrencyIndex, params)130 // console.log("signTransactionsAcceptAndPayMnemonicAsset txnPaymentAssetCurrency: ", txnPaymentAssetCurrency)131 const txnPaymentCommission = algosdk.makeAssetTransferTxnWithSuggestedParams(buyerAddress, commissionUCAddress, undefined, undefined, feeCommissionUC * 100, undefined, assetCurrencyIndex, params)132 // console.log("signTransactionsAcceptAndPayMnemonicAssetOptin txnPaymentCommission: ", txnPaymentCommission)133 let gid = algosdk.assignGroupID([txnPaymentAlgo, txnOptinAssetSowBuyer, txnPaymentAssetCurrency, txnPaymentCommission]);134 const secret_key = algosdk.mnemonicToSecretKey(mnemonicSecretKey);135 let signedTxnPaymentAlgo = algosdk.signTransaction(txnPaymentAlgo, secret_key.sk)136 signedTxnPaymentAlgo.blob = signedTxnPaymentAlgo.blob.toString()137 let signedTxnOptinAssetSowBuyer = algosdk.signTransaction(txnOptinAssetSowBuyer, secret_key.sk)138 signedTxnOptinAssetSowBuyer.blob = signedTxnOptinAssetSowBuyer.blob.toString()139 let signedTxnPaymentAssetCurrency = algosdk.signTransaction(txnPaymentAssetCurrency, secret_key.sk)140 signedTxnPaymentAssetCurrency.blob = signedTxnPaymentAssetCurrency.blob.toString()141 let signedTxnPaymentCommission = algosdk.signTransaction(txnPaymentCommission, secret_key.sk)142 signedTxnPaymentCommission.blob = signedTxnPaymentCommission.blob.toString()143 return [signedTxnPaymentAlgo, signedTxnOptinAssetSowBuyer, signedTxnPaymentAssetCurrency, signedTxnPaymentCommission]144 } catch (error) {145 console.log("signTransactionsAcceptAndPayMnemonicAsset API error: ", error)146 throw error147 }148}149// export function signTransactionsAcceptAndPayMnemonicAssetPaid(multiSigAddress: any, params: any, mnemonicSecretKey: any, toPay: any, buyer: any, assetId: any) {150// try {151// const txnOptin = algosdk.makeAssetTransferTxnWithSuggestedParams(buyer, buyer, undefined, undefined, 0, undefined, assetId, params)152// console.log("signTransactionsAcceptAndPayMnemonic txnOptin: ", txnOptin)153// const txnPayment = algosdk.makePaymentTxnWithSuggestedParams(buyer, multiSigAddress, toPay, undefined, undefined, params);154// console.log("signTransactionsAcceptAndPayMnemonic txnPayment: ", txnPayment)155// let gid = algosdk.assignGroupID([txnOptin, txnPayment]);156// const secret_key = algosdk.mnemonicToSecretKey(mnemonicSecretKey);157// let signedOptinTxn = algosdk.signTransaction(txnOptin, secret_key.sk)158// signedOptinTxn.blob = signedOptinTxn.blob.toString()159// let signedPaymentTxn = algosdk.signTransaction(txnPayment, secret_key.sk)160// signedPaymentTxn.blob = signedPaymentTxn.blob.toString()161// return [signedOptinTxn, signedPaymentTxn]162// } catch (error) {163// console.log("signTransactionsAcceptAndPayMnemonic API error: ", error)164// throw error165// }166// }167export const setSowArbitrator = async (sow: any, arbitrator: any) => {168 const mutation = loader('../graphql/setSowArbitrator.gql')169 try {170 const result: any = await API.graphql(graphqlOperation(mutation, { sow: sow, arbitrator: arbitrator }))171 // console.log("setSowArbitrator result: ", result)172 return result.data173 } catch (error) {174 console.log("setSowArbitrator API error: ", error)175 throw error176 }177}178export const algorandSendAcceptAndPayTx = async (sow: any, tx: any) => {179 const mutation = loader('../graphql/algorandSendAcceptAndPayTx.gql')180 try {181 const result: any = await API.graphql(graphqlOperation(mutation, { sow: sow, tx: tx }))182 console.log("algorandSendAcceptAndPayTx result: ", result)183 return result.data.algorandSendAcceptAndPayTx184 } catch (error) {185 console.log("algorandSendAcceptAndPayTx API error: ", error)186 throw error187 }188}189export function signMultisigTransaction(multiSigAddress: any, sellerAddress: any, params: any, mnemonicSecretKey: any, price: any, mparams: any) {190 try {191 const txn = {192 "from": multiSigAddress,193 "to": sellerAddress,194 "fee": params.fee,195 "amount": price * 1000000,196 "firstRound": params.firstRound,197 "lastRound": params.lastRound,198 "genesisID": params.genesisID,199 "genesisHash": params.genesisHash,200 "note": new Uint8Array(0)201 };202 const secret_key = algosdk.mnemonicToSecretKey(mnemonicSecretKey);203 const signedMultisigTxn = algosdk.signMultisigTransaction(txn, mparams, secret_key.sk);204 // console.log("in signMultisigTransaction signedMultisigTxn: ", signedMultisigTxn)205 return signedMultisigTxn206 } catch (error) {207 console.log("signMultisigTransaction API error: ", error)208 throw error209 }210}211export const setSignedMsig = async (sow: any, signedMsig: any) => {212 const mutation = loader('../graphql/setSignedMsig.gql')213 try {214 const result: any = await API.graphql(graphqlOperation(mutation, { sow: sow, signedMsig: signedMsig.blob.toString() }))215 // console.log("setSignedMsig result: ", result)216 return result.data.setSignedMsig217 } catch (error) {218 console.log("setSignedMsig API error: ", error)219 throw error220 }221}222export function signGroupAcceptMilestoneMnemonic(signedMsig: any, mnemonicSecretKey: any, msigparams: any) {223 try {224 const secret_key = algosdk.mnemonicToSecretKey(mnemonicSecretKey);225 const bufferMultisig = Uint8Array.from(signedMsig.tx[0].blob.split(',') as any);226 let signedMultisigPayment = algosdk.appendSignMultisigTransaction(bufferMultisig, msigparams, secret_key.sk);227 signedMultisigPayment.blob = signedMultisigPayment.blob.toString()228 console.log("in signGroupAcceptMilestone signedMultisigPayment: ", signedMultisigPayment)229 const bufferOptin: any = Uint8Array.from(signedMsig.tx[1].blob.split(',') as any);230 let signedOptinTxn = algosdk.signTransaction(algosdk.decodeUnsignedTransaction(bufferOptin), secret_key.sk)231 signedOptinTxn.blob = signedOptinTxn.blob.toString()232 console.log("in signGroupAcceptMilestone signedOptinTxn: ", signedOptinTxn)233 return [signedMultisigPayment, signedOptinTxn, signedMsig.tx[2]]234 } catch (error) {235 console.log("signGroupAcceptMilestone API error: ", error)236 throw error237 }238}239export const algorandPutTransaction = async (sow: any, tx: any) => {240 const mutation = loader('../graphql/algorandPutTransaction.gql')241 try {242 const result: any = await API.graphql(graphqlOperation(mutation, { sow: sow, blob: tx.blob.toString() }))243 console.log("algorandPutTransaction result: ", result)244 return result.data.algorandPutTransaction245 } catch (error) {246 console.log("algorandPutTransaction API error: ", error)247 throw error248 }249}250export const algorandPollAccountAmount = async (id: any, account: any, amount: any) => {251 const query = loader('../graphql/algorandPollAccountAmount.gql')252 try {253 const result: any = await API.graphql(graphqlOperation(query, { id: id, account: account, amount: amount }))254 // console.log("algorandPollAccountAmount result: ", result)255 return result.data.algorandPollAccountAmount256 } catch (error) {257 console.log("algorandPollAccountAmount API error: ", error)258 throw error259 }260}261export const algoConnect = async () => {262 try {263 let result = await AlgoSigner.connect();264 if (Object.keys(result).length === 0) {265 console.log("algoConnect result: ", result);266 return result;267 }268 else {269 console.log("algoConnect no result: ", result);270 }271 } catch (error) {272 console.log("algoConnect error: ", error)273 throw error274 }275}276export const algoGetAccounts = async () => {277 try {278 let accounts = await AlgoSigner.accounts({279 ledger: configuration[stage].algorand_net280 });281 console.log("algoGetAccounts accounts: ", accounts)282 var accountsInfo = [] as any283 for (let account of accounts) {284 accountsInfo.push(await AlgoSigner.algod({285 ledger: 'TestNet',286 path: '/v2/accounts/' + account.address,287 }))288 }289 console.log("algoGetAccounts accountsInfo: ", accountsInfo)290 return accountsInfo;291 } catch (error) {292 console.log("algoGetAccounts error: ", error)293 throw error294 }295}296export const createTransactionsAcceptAndPayAlgoSigner = async (multiSigAddress: any, params: any, toPay: any, buyer: any, assetId: any) => {297 try {298 let optinTxn: any = {299 from: buyer,300 to: buyer,301 closeRemainderTo: undefined,302 revocationTarget: undefined,303 amount: 0,304 note: undefined,305 assetIndex: assetId,306 fee: params.fee,307 firstRound: params.firstRound,308 lastRound: params.lastRound,309 genesisID: params.genesisID,310 genesisHash: params.genesisHash,311 rekeyTo: undefined,312 type: 'axfer'313 }314 // console.log("createTransactionsAcceptAndPayAlgoSigner optinTxn: ", optinTxn)315 let paymentTxn: any = {316 from: buyer,317 to: multiSigAddress,318 fee: params.fee,319 type: 'pay',320 amount: toPay,321 firstRound: params.firstRound,322 lastRound: params.lastRound,323 genesisID: params.genesisID,324 genesisHash: params.genesisHash,325 note: undefined326 }327 // console.log("createTransactionsAcceptAndPayAlgoSigner paymentTxn: ", paymentTxn)328 let gid = algosdk.assignGroupID([optinTxn, paymentTxn]);329 optinTxn.group = gid[1].group.toString('base64');330 paymentTxn.group = gid[0].group.toString('base64');331 // console.log("createTransactionsAcceptAndPayAlgoSigner optinTxn after group: ", optinTxn)332 // console.log("createTransactionsAcceptAndPayAlgoSigner paymentTxn after group: ", paymentTxn)333 return [optinTxn, paymentTxn]334 } catch (error) {335 console.log("createTransactionsAcceptAndPayAlgoSigner error: ", error)336 throw error337 }338}339export const createTransactionsAcceptAndPayPaidAlgoSigner = async (params: any, buyer: any, assetId: any) => {340 try {341 let optinTxn: any = {342 from: buyer,343 to: buyer,344 closeRemainderTo: undefined,345 revocationTarget: undefined,346 amount: 0,347 note: undefined,348 assetIndex: assetId,349 fee: params.fee,350 firstRound: params.firstRound,351 lastRound: params.lastRound,352 genesisID: params.genesisID,353 genesisHash: params.genesisHash,354 rekeyTo: undefined,355 type: 'axfer'356 }357 // console.log("createTransactionsAcceptAndPayPaidAlgoSigner optinTxn: ", optinTxn)358 return [optinTxn];359 } catch (error) {360 console.log("createTransactionsAcceptAndPayPaidAlgoSigner error: ", error)361 throw error362 }363}364export const algoSendTx = async (signedTxn: any) => {365 try {366 let result = await AlgoSigner.send({367 ledger: configuration[stage].algorand_net,368 tx: signedTxn.blob,369 });370 console.log("algoSendTx result: ", result);371 return result;372 } catch (error) {373 console.log("algoSendTx error: ", error)374 throw error375 }376}377export const requestReview = async (sow: any, notes: any) => {378 const mutation = loader('../graphql/requestReview.gql')379 try {380 const result: any = await API.graphql(graphqlOperation(mutation, { sow: sow, notes: notes }))381 console.log("requestReview result: ", result)382 return result.data.requestReview383 } catch (error) {384 console.log("requestReview API error: ", error)385 throw error386 }387}388export const algorandGetTx = async (sow: any) => {389 const query = loader('../graphql/algorandGetTx.gql')390 try {391 const result: any = await API.graphql(graphqlOperation(query, { sow: sow }))392 console.log("algorandGetTx result: ", result)393 return result.data.algorandGetTx394 } catch (error) {395 console.log("algorandGetTx API error: ", error)396 throw error397 }398}399export const algorandFinalizeTransaction = async (hash_round: any, round_sow: any, tx: any) => {400 const mutation = loader('../graphql/algorandFinalizeTransaction.gql')401 try {402 const result: any = await API.graphql(graphqlOperation(mutation, { hash_round: hash_round, round_sow: round_sow, tx: tx }))403 console.log("algorandFinalizeTransaction result: ", result)404 return result.data.algorandFinalizeTransaction405 } catch (error) {406 console.log("algorandFinalizeTransaction API error: ", error)407 throw error408 }409}410export function signTxn(mnemonicSecretKey: any, params: any, addr: any, note: any, totalIssuance: any, decimals: any, defaultFrozen: any, manager: any, reserve: any, freeze: any, clawback: any, unitName: any, assetName: any, assetURL: any, assetMetadataHash: any) {411 try {412 let creationTxn = algosdk.makeAssetCreateTxnWithSuggestedParams(413 addr,414 note,415 totalIssuance,416 decimals,417 defaultFrozen,418 manager,419 reserve,420 freeze,421 clawback,422 unitName,423 assetName,424 assetURL,425 assetMetadataHash,426 params427 );428 // console.log("signTxn txn: ", creationTxn)429 const secret_key = algosdk.mnemonicToSecretKey(mnemonicSecretKey);430 // const rawSignedCreationTxn = creationTxn.signTxn(secret_key.sk);431 let signedCreationTxn = algosdk.signTransaction(creationTxn, secret_key.sk)432 signedCreationTxn.blob = signedCreationTxn.blob.toString()433 // console.log("signTxn signedCreationTxn: ", signedCreationTxn)434 return [signedCreationTxn]435 } catch (error) {436 console.log("signTxn API error: ", error)437 throw error438 }439}440export const algorandSendTokenCreationTx = async (sow: any, tx: any) => {441 const mutation = loader('../graphql/algorandSendTokenCreationTx.gql')442 try {443 const result: any = await API.graphql(graphqlOperation(mutation, { sow: sow, tx: tx }))444 console.log("algorandSendTokenCreationTx result: ", result)445 return result.data.algorandSendTokenCreationTx446 } catch (error) {447 console.log("algorandSendTokenCreationTx API error: ", error)448 throw error449 }450}451export const algoSignSubmit = async (params: any, addr: any, note: any, totalIssuance: any, decimals: any, defaultFrozen: any, manager: any, reserve: any, freeze: any, clawback: any, unitName: any, assetName: any, assetURL: any, assetMetadataHash: any) => {452 try {453 let paramsAlgoSigner = await AlgoSigner.algod({454 ledger: configuration[stage].algorand_net,455 path: '/v2/transactions/params',456 });457 let creationTxn = algosdk.makeAssetCreateTxnWithSuggestedParams(458 addr,459 note,460 totalIssuance,461 decimals,462 defaultFrozen,463 manager,464 reserve,465 freeze,466 clawback,467 unitName,468 assetName,469 assetURL,470 assetMetadataHash,471 params472 );473 console.log("algoSignSubmit creationTxn: ", creationTxn)474 const algoTxn = {475 from: addr,476 assetName: creationTxn.assetName,477 assetUnitName: creationTxn.assetUnitName,478 assetTotal: creationTxn.assetTotal,479 assetDecimals: creationTxn.assetDecimals,480 note: creationTxn.note,481 type: creationTxn.type,482 fee: creationTxn.fee,483 firstRound: creationTxn.firstRound,484 lastRound: creationTxn.lastRound,485 genesisID: creationTxn.genesisID,486 genesisHash: creationTxn.genesisHash487 }488 let result = await AlgoSigner.sign(algoTxn)489 console.log("algoSign result: ", result);490 return result;491 } catch (error) {492 console.log("algoSign error: ", error)493 throw error494 }495}496export function mnemonicToSecretKey(mnemonicSecretKey: any) {497 try {498 const secret_key = algosdk.mnemonicToSecretKey(mnemonicSecretKey);499 // console.log("mnemonicToSecretKey secret_key: ", secret_key)500 return secret_key501 } catch (error) {502 console.log("mnemonicToSecretKey API error: ", error)503 throw error504 }505}506export const destroyAndCreateAssetMnemonic = async (mnemonicSecretKey: any, addr: any, note: any, assetID: any, params: any,507 totalIssuance: any, decimals: any, defaultFrozen: any, manager: any, reserve: any, freeze: any, clawback: any, unitName: any, assetName: any, assetURL: any, assetMetadataHash: any) => {508 try {509 const destroyTxn = algosdk.makeAssetDestroyTxnWithSuggestedParams(addr, note, assetID, params);510 // console.log("destroyAndCreateAssetMnemonic destroyTxn: ", destroyTxn);511 const creationTxn = algosdk.makeAssetCreateTxnWithSuggestedParams(512 addr,513 note,514 totalIssuance,515 decimals,516 defaultFrozen,517 manager,518 reserve,519 freeze,520 clawback,521 unitName,522 assetName,523 assetURL,524 assetMetadataHash,525 params526 );527 // console.log("destroyAndCreateAssetMnemonic creationTxn: ", creationTxn);528 let gid = algosdk.assignGroupID([destroyTxn, creationTxn]);529 const secret_key = algosdk.mnemonicToSecretKey(mnemonicSecretKey);530 let signedDestroyTxn = algosdk.signTransaction(destroyTxn, secret_key.sk)531 signedDestroyTxn.blob = signedDestroyTxn.blob.toString()532 let signedCreationTxn = algosdk.signTransaction(creationTxn, secret_key.sk)533 signedCreationTxn.blob = signedCreationTxn.blob.toString()534 const signedGroup = [signedDestroyTxn, signedCreationTxn]535 return signedGroup536 } catch (error) {537 console.log("destroyAndCreateAssetMnemonic error: ", error)538 throw error539 }540}541export const algorandSendDeliverableTokenCreationTx = async (sow: any, tx: any) => {542 const mutation = loader('../graphql/algorandSendDeliverableTokenCreationTx.gql')543 try {544 const result: any = await API.graphql(graphqlOperation(mutation, { sow: sow, tx: tx }))545 console.log("algorandSendDeliverableTokenCreationTx result: ", result)546 return result.data.algorandSendDeliverableTokenCreationTx547 } catch (error) {548 console.log("algorandSendDeliverableTokenCreationTx API error: ", error)549 throw error550 }551}552export function signTransactionsClaimMilestoneMetMnemonicAlgo(multiSigAddress: any, sellerAddress: any, params: any, mnemonicSecretKey: any, price: any, mparams: any, buyerAddress: any, assetId: any) {553 try {554 let txnPayment = algosdk.makePaymentTxnWithSuggestedParams(multiSigAddress, sellerAddress, price * 1000000, undefined, undefined, params);555 // console.log("signTransactionsClaimMilestoneMetMnemonic txnPayment: ", txnPayment)556 let txnPaymentGroup = algosdk.makePaymentTxnWithSuggestedParams(multiSigAddress, sellerAddress, price * 1000000, undefined, undefined, params);557 // console.log("signTransactionsClaimMilestoneMetMnemonicAlgo txnPaymentGroup: ", txnPaymentGroup)558 const txnOptin = algosdk.makeAssetTransferTxnWithSuggestedParams(buyerAddress, buyerAddress, undefined, undefined, 0, undefined, assetId, params)559 // console.log("signTransactionsClaimMilestoneMetMnemonicAlgo txnOptin: ", txnOptin)560 const txnAsset = algosdk.makeAssetTransferTxnWithSuggestedParams(sellerAddress, buyerAddress, undefined, undefined, 1, undefined, assetId, params)561 // console.log("signTransactionsClaimMilestoneMetMnemonic txnAsset: ", txnAsset)562 let gid = algosdk.assignGroupID([txnPaymentGroup, txnOptin, txnAsset]);563 const secret_key = algosdk.mnemonicToSecretKey(mnemonicSecretKey);564 let signedPaymentTxn = algosdk.signMultisigTransaction(txnPayment, mparams, secret_key.sk);565 signedPaymentTxn.blob = signedPaymentTxn.blob.toString()566 let signedPaymentTxnGroup = algosdk.signMultisigTransaction(txnPaymentGroup, mparams, secret_key.sk);567 signedPaymentTxnGroup.blob = signedPaymentTxnGroup.blob.toString()568 let parsedOptinTxn = {569 txID: "unknown",570 blob: algosdk.encodeObj(txnOptin.get_obj_for_encoding()).toString()571 }572 let signedAssetTxn = algosdk.signTransaction(txnAsset, secret_key.sk)573 signedAssetTxn.blob = signedAssetTxn.blob.toString()574 const signedGroup = [signedPaymentTxnGroup, parsedOptinTxn, signedAssetTxn]575 return { tx: signedGroup, backupTx: [signedPaymentTxn] }576 } catch (error) {577 console.log("signTransactionsClaimMilestoneMetMnemonic API error: ", error)578 throw error579 }580}581export function signTransactionsClaimMilestoneMetMnemonicAsset(multiSigAddress: any, sellerAddress: any, params: any, mnemonicSecretKey: any, price: any, mparams: any, buyerAddress: any, assetIdDeliverable: any, assetIdCurrency: any) {582 try {583 const txnPaymentAssetBackup = algosdk.makeAssetTransferTxnWithSuggestedParams(multiSigAddress, sellerAddress, undefined, undefined, price * 100, undefined, assetIdCurrency, params)584 // console.log("signTransactionsClaimMilestoneMetMnemonic txnPayment: ", txnPayment)585 const txnPaymentAssetGroup = algosdk.makeAssetTransferTxnWithSuggestedParams(multiSigAddress, sellerAddress, undefined, undefined, price * 100, undefined, assetIdCurrency, params)586 // console.log("signTransactionsClaimMilestoneMetMnemonicAlgo txnPaymentGroup: ", txnPaymentGroup)587 const txnOptin = algosdk.makeAssetTransferTxnWithSuggestedParams(buyerAddress, buyerAddress, undefined, undefined, 0, undefined, assetIdDeliverable, params)588 // console.log("signTransactionsClaimMilestoneMetMnemonicAlgo txnOptin: ", txnOptin)589 const txnAssetDelierable = algosdk.makeAssetTransferTxnWithSuggestedParams(sellerAddress, buyerAddress, undefined, undefined, 1, undefined, assetIdDeliverable, params)590 // console.log("signTransactionsClaimMilestoneMetMnemonic txnAsset: ", txnAsset)591 let gid = algosdk.assignGroupID([txnPaymentAssetGroup, txnOptin, txnAssetDelierable]);592 const secret_key = algosdk.mnemonicToSecretKey(mnemonicSecretKey);593 let signedTxnPaymentAssetBackup = algosdk.signMultisigTransaction(txnPaymentAssetBackup, mparams, secret_key.sk);594 signedTxnPaymentAssetBackup.blob = signedTxnPaymentAssetBackup.blob.toString()595 let signedTxnPaymentAssetGroup = algosdk.signMultisigTransaction(txnPaymentAssetGroup, mparams, secret_key.sk);596 signedTxnPaymentAssetGroup.blob = signedTxnPaymentAssetGroup.blob.toString()597 let parsedTxnOptin = {598 txID: "unknown",599 blob: algosdk.encodeObj(txnOptin.get_obj_for_encoding()).toString()600 }601 let signedTxnAssetDelierable = algosdk.signTransaction(txnAssetDelierable, secret_key.sk)602 signedTxnAssetDelierable.blob = signedTxnAssetDelierable.blob.toString()603 const signedGroup = [signedTxnPaymentAssetGroup, parsedTxnOptin, signedTxnAssetDelierable]604 return { tx: signedGroup, backupTx: [signedTxnPaymentAssetBackup] }605 } catch (error) {606 console.log("signTransactionsClaimMilestoneMetMnemonic API error: ", error)607 throw error608 }609}610export const createTransactionsClaimMilestonMetAlgoSigner = async (multiSigAddress: any, sellerAddress: any, params: any, price: any, buyerAddress: any, assetId: any) => {611 try {612 let txnPayment: any = {613 from: multiSigAddress,614 to: sellerAddress,615 amount: price * 1000000,616 closeRemainderTo: undefined,617 note: undefined,618 fee: params.fee,619 firstRound: params.firstRound,620 lastRound: params.lastRound,621 genesisID: params.genesisID,622 genesisHash: params.genesisHash,623 type: 'pay'624 }625 // console.log("createTransactionsClaimMilestonMetAlgoSigner txnPayment: ", txnPayment)626 let txnPaymentGroup: any = {627 from: multiSigAddress,628 to: sellerAddress,629 amount: price * 1000000,630 closeRemainderTo: undefined,631 note: undefined,632 fee: params.fee,633 firstRound: params.firstRound,634 lastRound: params.lastRound,635 genesisID: params.genesisID,636 genesisHash: params.genesisHash,637 type: 'pay'638 }639 // console.log("createTransactionsClaimMilestonMetAlgoSigner txnPaymentGroup: ", txnPaymentGroup)640 const txnOptin = algosdk.makeAssetTransferTxnWithSuggestedParams(buyerAddress, buyerAddress, undefined, undefined, 0, undefined, assetId, params)641 // console.log("createTransactionsClaimMilestonMetAlgoSigner txnOptin: ", txnOptin)642 let txnAsset: any = {643 from: sellerAddress,644 to: buyerAddress,645 closeRemainderTo: undefined,646 revocationTarget: undefined,647 amount: 1,648 note: undefined,649 assetIndex: assetId,650 fee: params.fee,651 firstRound: params.firstRound,652 lastRound: params.lastRound,653 genesisID: params.genesisID,654 genesisHash: params.genesisHash,655 rekeyTo: undefined,656 type: 'axfer'657 }658 // console.log("createTransactionsClaimMilestonMetAlgoSigner txnAsset: ", txnAsset)659 let gid = algosdk.assignGroupID([txnPaymentGroup, txnOptin, txnAsset]);660 txnPaymentGroup.group = gid[1].group.toString('base64');661 let parsedOptinTxn: any = {662 txID: "unknown",663 blob: algosdk.encodeObj(txnOptin.get_obj_for_encoding()).toString()664 }665 txnAsset.group = gid[1].group.toString('base64');666 let groupTxn = [txnPaymentGroup, parsedOptinTxn, txnAsset]667 return { tx: groupTxn, backupTx: txnPayment }668 } catch (error) {669 console.log("createTransactionsClaimMilestonMetAlgoSigner error: ", error)670 throw error671 }672}673export const algorandSendClaimMilestoneMet = async (sow: any, tx: any, backupTx: any) => {674 const mutation = loader('../graphql/algorandSendClaimMilestoneMet.gql')675 try {676 const result: any = await API.graphql(graphqlOperation(mutation, { sow: sow, tx: tx, backupTx: backupTx }))677 console.log("algorandSendClaimMilestoneMet result: ", result)678 return result.data.algorandSendClaimMilestoneMet679 } catch (error) {680 console.log("algorandSendClaimMilestoneMet API error: ", error)681 throw error682 }683}684export const destroyAndCreateAssetAlgoSigner = async (addr: any, note: any, assetID: any, params: any,685 totalIssuance: any, decimals: any, defaultFrozen: any, manager: any, reserve: any, freeze: any, clawback: any, unitName: any, assetName: any, assetURL: any, assetMetadataHash: any686) => {687 try {688 const destroyTxn = {689 from: addr,690 note: note,691 assetIndex: assetID,692 type: 'acfg',693 fee: params.fee,694 firstRound: params.firstRound,695 lastRound: params.lastRound,696 genesisID: params.genesisID,697 genesisHash: params.genesisHash698 }699 const creationTxn = {700 from: addr,701 assetName: assetName,702 assetUnitName: unitName,703 assetTotal: totalIssuance,704 assetDecimals: decimals,705 note: note,706 type: 'acfg',707 fee: params.fee,708 firstRound: params.firstRound,709 lastRound: params.lastRound,710 genesisID: params.genesisID,711 genesisHash: params.genesisHash,712 assetManager: manager,713 assetReserve: reserve,714 assetFreeze: freeze,715 assetClawback: clawback,716 assetURL: assetURL,717 assetMetadataHash: assetMetadataHash718 }719 console.log("destroyAndCreateAssetAlgoSigner destroyTxn: ", destroyTxn);720 console.log("destroyAndCreateAssetAlgoSigner creationTxn: ", creationTxn);721 let gid = algosdk.assignGroupID([destroyTxn, creationTxn]);722 console.log("destroyAndCreateAssetAlgoSigner gid after group: ", gid);723 console.log("destroyAndCreateAssetAlgoSigner destroyTxn after group: ", destroyTxn);724 console.log("destroyAndCreateAssetAlgoSigner creationTxn after group: ", creationTxn);725 return [destroyTxn, creationTxn]726 // let signedDestroyTxn = await AlgoSigner.sign(destroyTxn)727 // signedDestroyTxn.blob = Uint8Array.from(signedDestroyTxn.blob.split("").map((x: any) => x.charCodeAt(0))).toString()728 // console.log("destroyAndCreateAssetAlgoSigner signedDestroyTxn: ", signedDestroyTxn);729 // let signedCreationTxn = await AlgoSigner.sign(creationTxn)730 // signedCreationTxn.blob = Uint8Array.from(signedCreationTxn.blob.split("").map((x: any) => x.charCodeAt(0))).toString()731 // console.log("destroyAndCreateAssetAlgoSigner signedCreationTxn: ", signedCreationTxn);732 // const signedGroup = [signedDestroyTxn, signedCreationTxn]733 // return signedGroup734 } catch (error) {735 console.log("destroyAndCreateAssetAlgoSigner error: ", error)736 throw error737 }738}739export const createAssetAlgoSigner = async (addr: any, note: any, params: any,740 totalIssuance: any, decimals: any, defaultFrozen: any, manager: any, reserve: any, freeze: any, clawback: any, unitName: any, assetName: any, assetURL: any, assetMetadataHash: any) => {741 try {742 const creationTxn = {743 from: addr,744 assetName: assetName,745 assetUnitName: unitName,746 assetTotal: totalIssuance,747 assetDecimals: decimals,748 note: note,749 type: 'acfg',750 fee: params.fee,751 firstRound: params.firstRound,752 lastRound: params.lastRound,753 genesisID: params.genesisID,754 genesisHash: params.genesisHash,755 assetManager: manager,756 assetReserve: reserve,757 assetFreeze: freeze,758 assetClawback: clawback,759 assetURL: assetURL,760 assetMetadataHash: assetMetadataHash761 }762 // console.log("createAssetAlgoSigner creationTxn: ", creationTxn);763 let signedCreationTxn = await AlgoSigner.sign(creationTxn)764 // console.log("createAssetAlgoSigner signedCreationTxn after sign: ", signedCreationTxn);765 signedCreationTxn.blob = atob(signedCreationTxn.blob).split('').map((x) => x.charCodeAt(0)).toString()766 // console.log("createAssetAlgoSigner signedCreationTxn after split: ", signedCreationTxn);767 return [signedCreationTxn]768 } catch (error) {769 console.log("createAssetAlgoSigner error: ", error)770 throw error771 }772}773export const createTransactionsAcceptMilestoneAlgoSigner = async (group: any) => {774 try {775 // payment776 const blob1Splitted = Buffer.from(group[0].blob.split(','));777 console.log("createTransactionsAcceptMilestoneAlgoSigner blob1Splitted: ", blob1Splitted);778 let newmsig = JSON.stringify(algosdk.decodeObj(blob1Splitted).msig, _toJsonReplace, 0);779 console.log("createTransactionsAcceptMilestoneAlgoSigner newmsig: ", JSON.parse(newmsig));780 const blobDecoded = algosdk.decodeObj(blob1Splitted)781 console.log("createTransactionsAcceptMilestoneAlgoSigner blobDecoded: ", blobDecoded);782 console.log("createTransactionsAcceptMilestoneAlgoSigner blobDecoded.msig: ", blobDecoded.msig);783 const blobDecodedNew = {784 msig: JSON.parse(newmsig),785 txn: {786 flatFee: true,787 fee: blobDecoded.txn.fee,788 to: algosdk.encodeAddress(blobDecoded.txn.rcv),789 amount: blobDecoded.txn.amt,790 from: algosdk.encodeAddress(blobDecoded.txn.snd),791 firstRound: blobDecoded.txn.fv,792 lastRound: blobDecoded.txn.lv,793 genesisID: blobDecoded.txn.gen,794 genesisHash: Buffer.from(blobDecoded.txn.gh).toString("base64"),795 group: Buffer.from(blobDecoded.txn.grp).toString("base64"),796 type: 'pay'797 }798 }799 console.log("createTransactionsAcceptMilestoneAlgoSigner blobDecodedNew: ", blobDecodedNew);800 // optin801 console.log("createTransactionsAcceptMilestoneAlgoSigner group[1]:", group[1])802 let group1 = algosdk.decodeObj(Buffer.from(group[1].blob.split(',')))803 console.log("createTransactionsAcceptMilestoneAlgoSigner group1:", group1)804 let optinTxn: any = {805 flatFee: true,806 from: algosdk.encodeAddress(group1.snd),807 to: algosdk.encodeAddress(group1.arcv),808 closeRemainderTo: undefined,809 revocationTarget: undefined,810 amount: 0,811 note: undefined,812 assetIndex: group1.xaid,813 fee: group1.fee,814 firstRound: group1.fv,815 lastRound: group1.lv,816 genesisID: group1.gen,817 genesisHash: Buffer.from(group1.gh).toString("base64"),818 rekeyTo: undefined,819 type: 'axfer',820 group: Buffer.from(group1.grp).toString("base64")821 }822 console.log("createTransactionsAcceptMilestoneAlgoSigner optinTxn: ", optinTxn);823 return { payment: { blob1Splitted: blob1Splitted, blobDecodedNew: blobDecodedNew }, optin: optinTxn }824 } catch (error) {825 console.log("createTransactionsAcceptMilestoneAlgoSigner error: ", error)826 throw error827 }828}829export const signTxAlgoSigner = async (tx: any) => {830 try {831 console.log("signTxAlgoSigner tx: ", tx);832 let signedTx = await AlgoSigner.sign(tx)833 signedTx.blob = atob(signedTx.blob).split('').map((x) => x.charCodeAt(0)).toString()834 console.log("signTxAlgoSigner signedTx: ", signedTx);835 return signedTx836 } catch (error) {837 console.log("signTxAlgoSigner error: ", error)838 throw error839 }840}841export const signMultisigTxAlgoSigner = async (tx: any, msig: any) => {842 try {843 console.log("signMultisigTxAlgoSigner tx: ", tx);844 console.log("signMultisigTxAlgoSigner msig: ", msig);845 const msig_txn = {846 msig: {847 subsig: [848 { pk: msig[0] },849 { pk: msig[1] },850 { pk: msig[2] },851 { pk: msig[3] },852 ],853 thr: 2,854 v: 1855 },856 txn: tx857 };858 let signedTx = await AlgoSigner.signMultisig(msig_txn)859 signedTx.blob = atob(signedTx.blob).split('').map((x) => x.charCodeAt(0)).toString()860 console.log("signMultisigTxAlgoSigner signedTx after split: ", signedTx);861 return signedTx862 } catch (error) {863 console.log("signMultisigTxAlgoSigner error: ", error)864 throw error865 }866}867export const signAppendMultisigTxAlgoSigner = async (tx: any) => {868 try {869 console.log("signAppendMultisigTxAlgoSigner tx.blob1Splitted: ", tx.blob1Splitted)870 console.log("signAppendMultisigTxAlgoSigner tx.blobDecodedNew: ", tx.blobDecodedNew)871 let signedTx = await AlgoSigner.signMultisig(tx.blobDecodedNew)872 signedTx.blob = atob(signedTx.blob).split('').map((x) => x.charCodeAt(0))873 let from64bit_T1 = new Uint8Array(tx.blob1Splitted);874 let from64bit_T2 = new Uint8Array(signedTx.blob);875 // console.log("signAppendMultisigTxAlgoSigner from64bit_T1: ", algosdk.decodeObj(from64bit_T1))876 // console.log("signAppendMultisigTxAlgoSigner from64bit_T2: ", algosdk.decodeObj(from64bit_T2))877 const mergedTx = algosdk.mergeMultisigTransactions([from64bit_T1, from64bit_T2]).toString()878 // console.log("signAppendMultisigTxAlgoSigner mergedTx: ", mergedTx)879 return { txID: signedTx.txID, blob: mergedTx }880 } catch (error) {881 console.log("signAppendMultisigTxAlgoSigner error: ", error)882 throw error883 }884}885function _toJsonReplace(key, value) {886 // Return value immediately if null or undefined887 if (value === undefined || value === null) {888 return value;889 }890 // Check for uint8 arrays to get buffer for print891 if (value instanceof Uint8Array || (typeof (value) === 'object' && value instanceof Array && value.length > 0 && typeof (value[0]) === 'number')) {892 let wasUpdated = false;893 try {894 let newvalue = algosdk.encodeAddress(value);895 if (algosdk.isValidAddress(newvalue)) {896 value = newvalue;897 wasUpdated = true;898 }899 }900 catch (e) {901 // Ignore as this error since it is just display related and a forced decode and fallback to a normal base64 to ascii 902 }903 if (!wasUpdated) {904 value = btoa(String.fromCharCode.apply(null, value));905 }906 return value;907 }908 // Check for literal string match on object type to cycle further into the recursive replace909 if (value === '[object Object]') {910 return JSON.stringify(value, _toJsonReplace, 2);911 }912 // Return without modification913 return value;...

Full Screen

Full Screen

MarketPlace.ts

Source:MarketPlace.ts Github

copy

Full Screen

1import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";2import { expect } from "chai";3import { Contract } from "ethers";4import { ethers } from "hardhat";5describe("MarketPlace contract", () => {6 let nft: Contract;7 let marketPlace: Contract;8 let nftContractAddress: any;9 let marketPlaceContractAddress: any;10 let owner: SignerWithAddress;11 let addr1: SignerWithAddress;12 const LISTING_FEE = '25000000000000000';13 beforeEach('Setup Contracts', async () => {14 const EternalNFT = await ethers.getContractFactory('NFT');15 const nftTxn = await EternalNFT.deploy();16 nft = await nftTxn.deployed();17 nftContractAddress = nft.address;18 const NFTMarketplace = await ethers.getContractFactory("MarketPlace");19 const marketPlaceTxn = await NFTMarketplace.deploy(nftContractAddress);20 marketPlace = await marketPlaceTxn.deployed();21 marketPlaceContractAddress = marketPlace.address;22 [owner, addr1] = await ethers.getSigners();23 });24 describe('Listing Fee', async () => {25 it('Should be able to get the listing fee', async () => {26 const listingFeeTxn = await marketPlace.connect(owner).getListingFee();27 expect(listingFeeTxn).to.be.equal(LISTING_FEE);28 });29 it('Should be able get the total collected listing fee', async () => {30 const collectionTxn = await marketPlace.connect(owner).createCollection('image1', 'name2', 'description1');31 const collectionTx = await collectionTxn.wait();32 const collectionId = collectionTx.events[0].args.collectionId.toNumber();33 const tokenTxn = await marketPlace.connect(owner).mintToken('tokenURI', 'name', 'description', collectionId);34 const tokenTx = await tokenTxn.wait();35 const tokenId = tokenTx.events[1].args.tokenId.toNumber();36 const listingFee = await marketPlace.connect(owner).getListingFee();37 const saleTxn = await marketPlace.connect(owner).createSale(tokenId, 10, { value: listingFee });38 await saleTxn.wait();39 const collectedListingFeeTxn = await marketPlace.connect(owner).getCollectedListingFee();40 expect(collectedListingFeeTxn).to.be.equal(LISTING_FEE);41 });42 it('Should be able to transfer the collected listing fee', async () => {43 const collectionTxn = await marketPlace.connect(owner).createCollection('image1', 'name2', 'description1');44 const collectionTx = await collectionTxn.wait();45 const collectionId = collectionTx.events[0].args.collectionId.toNumber();46 const tokenTxn = await marketPlace.connect(owner).mintToken('tokenURI', 'name', 'description', collectionId);47 const tokenTx = await tokenTxn.wait();48 const tokenId = tokenTx.events[1].args.tokenId.toNumber();49 const listingFee = await marketPlace.connect(owner).getListingFee();50 const saleTxn = await marketPlace.connect(owner).createSale(tokenId, 10, { value: listingFee });51 await saleTxn.wait();52 const transferListingFeeTxn = await marketPlace.connect(owner).transferListingFee();53 await transferListingFeeTxn.wait();54 const collectedListingFeeTxn = await marketPlace.connect(owner).getCollectedListingFee();55 expect(collectedListingFeeTxn).to.be.equal(0);56 });57 });58 describe('Creator info', async () => {59 it('Should be able to change creator\'s name', async () => {60 const changeNameTxn = await marketPlace.connect(owner).changeCreatorName('new name');61 const changeNameTx = await changeNameTxn.wait();62 const newName = changeNameTx.events[0].args.name;63 expect(newName).to.be.equal('new name');64 });65 it('Should be able to change creator\'s image', async () => {66 const changeImageTxn = await marketPlace.connect(owner).changeCreatorImage('new image');67 const changeImageTx = await changeImageTxn.wait();68 const newImage = changeImageTx.events[0].args.image;69 expect(newImage).to.be.equal('new image');70 });71 });72 describe('Creating collection', async () => {73 it('Should be able to create collection', async () => {74 const txn = await marketPlace.connect(owner).createCollection('image', 'name', 'description');75 const tokenTx = await txn.wait();76 const collectionId = tokenTx.events[0].args.collectionId.toNumber();77 expect(collectionId).to.be.equal(1);78 });79 it('Should be able get collections total length', async () => {80 const txn = await marketPlace.connect(owner).createCollection('image', 'name', 'description');81 await txn.wait();82 const length = await marketPlace.connect(owner).getCollectionLength();83 expect(length).to.be.equal(1);84 });85 });86 describe('Minting NFT', () => {87 it('Should be able to mint a new token', async () => {88 const collectionTxn = await marketPlace.connect(owner).createCollection('image1', 'name2', 'description1');89 const collectionTx = await collectionTxn.wait();90 const collectionId = collectionTx.events[0].args.collectionId.toNumber();91 const tokenTxn = await marketPlace.connect(owner).mintToken('tokenURI', 'name', 'description', collectionId);92 const tokenTx = await tokenTxn.wait();93 const tokenId = tokenTx.events[1].args.tokenId.toNumber();94 expect(tokenId).to.be.equal(1);95 });96 it('Should fail to mint a new token for non existent collection', async () => {97 await expect(marketPlace.connect(owner).mintToken('tokenURI', 'name', 'description', 2)).to.be.revertedWith("Marketplace: no collection of yours");98 });99 it('Should be able get items total length', async () => {100 const collectionTxn = await marketPlace.connect(owner).createCollection('image1', 'name2', 'description1');101 const collectionTx = await collectionTxn.wait();102 const collectionId = collectionTx.events[0].args.collectionId.toNumber();103 const txn1 = await marketPlace.connect(owner).mintToken('tokenURI', 'name', 'description', collectionId);104 await txn1.wait();105 const length = await marketPlace.connect(owner).getMarketItemsLength();106 expect(length).to.be.equal(1);107 });108 });109 describe('Market Sale', () => {110 it('Should be able to create market sale', async () => {111 const collectionTxn = await marketPlace.connect(owner).createCollection('image1', 'name2', 'description1');112 const collectionTx = await collectionTxn.wait();113 const collectionId = collectionTx.events[0].args.collectionId.toNumber();114 const tokenTxn = await marketPlace.connect(owner).mintToken('tokenURI', 'name', 'description', collectionId);115 const tokenTx = await tokenTxn.wait();116 const tokenId = tokenTx.events[1].args.tokenId.toNumber();117 const listingFee = await marketPlace.connect(owner).getListingFee();118 const saleTxn = await marketPlace.connect(owner).createSale(tokenId, 10, { value: listingFee });119 const saleTx = await saleTxn.wait();120 const tokenPrice = saleTx.events[0].args.price;121 expect(tokenPrice).to.be.equal(10);122 });123 it('Should fail to create sale if token does not exist', async () => {124 await expect(marketPlace.connect(owner).createSale(1, 10, { value: LISTING_FEE })).to.be.revertedWith("Marketplace: no such token");125 });126 it('Should fail to create sale if token does not belong to owner', async () => {127 const collectionTxn = await marketPlace.connect(owner).createCollection('image1', 'name2', 'description1');128 const collectionTx = await collectionTxn.wait();129 const collectionId = collectionTx.events[0].args.collectionId.toNumber();130 const tokenTxn = await marketPlace.connect(owner).mintToken('tokenURI', 'name', 'description', collectionId);131 const tokenTx = await tokenTxn.wait();132 const tokenId = tokenTx.events[1].args.tokenId.toNumber();133 await expect(marketPlace.connect(addr1).createSale(tokenId, 10, { value: LISTING_FEE })).to.be.revertedWith("Marketplace: token is not owned by you");134 });135 it('Should fail to create sale if value is different from listing fee', async () => {136 const collectionTxn = await marketPlace.connect(owner).createCollection('image1', 'name2', 'description1');137 const collectionTx = await collectionTxn.wait();138 const collectionId = collectionTx.events[0].args.collectionId.toNumber();139 const tokenTxn = await marketPlace.connect(owner).mintToken('tokenURI', 'name', 'description', collectionId);140 const tokenTx = await tokenTxn.wait();141 const tokenId = tokenTx.events[1].args.tokenId.toNumber();142 await expect(marketPlace.connect(owner).createSale(tokenId, 10, { value: 0 })).to.be.revertedWith("Marketplace: price must be equal to listing price");143 });144 it('Should be able to cancel market sale', async () => {145 const collectionTxn = await marketPlace.connect(owner).createCollection('image1', 'name2', 'description1');146 const collectionTx = await collectionTxn.wait();147 const collectionId = collectionTx.events[0].args.collectionId.toNumber();148 const tokenTxn = await marketPlace.connect(owner).mintToken('tokenURI', 'name', 'description', collectionId);149 const tokenTx = await tokenTxn.wait();150 const tokenId = tokenTx.events[1].args.tokenId.toNumber();151 const listingFee = await marketPlace.connect(owner).getListingFee();152 const saleTxn = await marketPlace.connect(owner).createSale(tokenId, 10, { value: listingFee });153 await saleTxn.wait();154 const cancelSaleTxn = await marketPlace.connect(owner).cancelSale(tokenId);155 await cancelSaleTxn.wait();156 const token = await marketPlace.connect(owner).marketItems(1);157 expect(token.status).to.be.equal(1);158 });159 it('Should fail to cancel sale if token is not for sale', async () => {160 const collectionTxn = await marketPlace.connect(owner).createCollection('image1', 'name2', 'description1');161 const collectionTx = await collectionTxn.wait();162 const collectionId = collectionTx.events[0].args.collectionId.toNumber();163 const tokenTxn = await marketPlace.connect(owner).mintToken('tokenURI', 'name', 'description', collectionId);164 const tokenTx = await tokenTxn.wait();165 const tokenId = tokenTx.events[1].args.tokenId.toNumber();166 await expect(marketPlace.connect(owner).cancelSale(tokenId)).to.be.revertedWith("Marketplace: item is not for sale");167 });168 it('Should be able to buy market item', async () => {169 const collectionTxn = await marketPlace.connect(owner).createCollection('image1', 'name2', 'description1');170 const collectionTx = await collectionTxn.wait();171 const collectionId = collectionTx.events[0].args.collectionId.toNumber();172 const tokenTxn = await marketPlace.connect(owner).mintToken('tokenURI', 'name', 'description', collectionId);173 const tokenTx = await tokenTxn.wait();174 const tokenId = tokenTx.events[1].args.tokenId.toNumber();175 const listingFee = await marketPlace.connect(owner).getListingFee();176 const saleTxn = await marketPlace.connect(owner).createSale(tokenId, 10, { value: listingFee });177 const saleTx = await saleTxn.wait();178 const tokenPrice = saleTx.events[0].args.price;179 const approveTxn = await nft.connect(owner).approve(marketPlaceContractAddress, tokenId);180 await approveTxn.wait();181 const buyTxn = await marketPlace.connect(addr1).buyMarketItem(tokenId, { value: tokenPrice });182 await buyTxn.wait();183 const newOwner = await nft.ownerOf(tokenId);184 expect(newOwner).to.be.equal(addr1.address);185 });186 it('Should fail to buy market item if buyer is the creator', async () => {187 const collectionTxn = await marketPlace.connect(owner).createCollection('image1', 'name2', 'description1');188 const collectionTx = await collectionTxn.wait();189 const collectionId = collectionTx.events[0].args.collectionId.toNumber();190 const tokenTxn = await marketPlace.connect(owner).mintToken('tokenURI', 'name', 'description', collectionId);191 const tokenTx = await tokenTxn.wait();192 const tokenId = tokenTx.events[1].args.tokenId.toNumber();193 const listingFee = await marketPlace.connect(owner).getListingFee();194 const saleTxn = await marketPlace.connect(owner).createSale(tokenId, 10, { value: listingFee });195 const saleTx = await saleTxn.wait();196 const tokenPrice = saleTx.events[0].args.price;197 const approveTxn = await nft.connect(owner).approve(marketPlaceContractAddress, tokenId);198 await approveTxn.wait();199 await expect(marketPlace.connect(owner).buyMarketItem(tokenId, { value: tokenPrice })).to.be.revertedWith("Marketplace: you can not buy your own item");200 });201 it('Should fail to buy market item if not correct amount is given', async () => {202 const collectionTxn = await marketPlace.connect(owner).createCollection('image1', 'name2', 'description1');203 const collectionTx = await collectionTxn.wait();204 const collectionId = collectionTx.events[0].args.collectionId.toNumber();205 const tokenTxn = await marketPlace.connect(owner).mintToken('tokenURI', 'name', 'description', collectionId);206 const tokenTx = await tokenTxn.wait();207 const tokenId = tokenTx.events[1].args.tokenId.toNumber();208 const listingFee = await marketPlace.connect(owner).getListingFee();209 const saleTxn = await marketPlace.connect(owner).createSale(tokenId, 10, { value: listingFee });210 await saleTxn.wait();211 const approveTxn = await nft.connect(owner).approve(marketPlaceContractAddress, tokenId);212 await approveTxn.wait();213 await expect(marketPlace.connect(addr1).buyMarketItem(tokenId, { value: 0 })).to.be.revertedWith("Marketplace: amount must be equal to the item listing price");214 });215 });216 describe('Bid on items', () => {217 it('Should be able to bid on market item', async () => {218 const collectionTxn = await marketPlace.connect(owner).createCollection('image1', 'name2', 'description1');219 const collectionTx = await collectionTxn.wait();220 const collectionId = collectionTx.events[0].args.collectionId.toNumber();221 const tokenTxn = await marketPlace.connect(owner).mintToken('tokenURI', 'name', 'description', collectionId);222 const tokenTx = await tokenTxn.wait();223 const tokenId = tokenTx.events[1].args.tokenId.toNumber();224 const bidTxn = await marketPlace.connect(addr1).bidMarketItem(tokenId, { value: 1000 });225 const bidTx = await bidTxn.wait();226 const bidder = bidTx.events[0].args.bidder;227 expect(bidder).to.be.equal(addr1.address);228 });229 it('Should fail to bid on market item if bid is zero', async () => {230 const collectionTxn = await marketPlace.connect(owner).createCollection('image1', 'name2', 'description1');231 const collectionTx = await collectionTxn.wait();232 const collectionId = collectionTx.events[0].args.collectionId.toNumber();233 const tokenTxn = await marketPlace.connect(owner).mintToken('tokenURI', 'name', 'description', collectionId);234 const tokenTx = await tokenTxn.wait();235 const tokenId = tokenTx.events[1].args.tokenId.toNumber();236 await expect(marketPlace.connect(addr1).bidMarketItem(tokenId, { value: 0 })).to.be.revertedWith("Marketplace: bid must be at least one wei");237 });238 it('Should fail to bid on market item if bidder is the creator', async () => {239 const collectionTxn = await marketPlace.connect(owner).createCollection('image1', 'name2', 'description1');240 const collectionTx = await collectionTxn.wait();241 const collectionId = collectionTx.events[0].args.collectionId.toNumber();242 const tokenTxn = await marketPlace.connect(owner).mintToken('tokenURI', 'name', 'description', collectionId);243 const tokenTx = await tokenTxn.wait();244 const tokenId = tokenTx.events[1].args.tokenId.toNumber();245 await expect(marketPlace.connect(owner).bidMarketItem(tokenId, { value: 1000 })).to.be.revertedWith("Marketplace: you can not bid your own item");246 });247 it('Should be able get bids total length', async () => {248 const collectionTxn = await marketPlace.connect(owner).createCollection('image1', 'name2', 'description1');249 const collectionTx = await collectionTxn.wait();250 const collectionId = collectionTx.events[0].args.collectionId.toNumber();251 const tokenTxn = await marketPlace.connect(owner).mintToken('tokenURI', 'name', 'description', collectionId);252 const tokenTx = await tokenTxn.wait();253 const tokenId = tokenTx.events[1].args.tokenId.toNumber();254 const bidTxn = await marketPlace.connect(addr1).bidMarketItem(tokenId, { value: 1000 });255 await bidTxn.wait();256 const length = await marketPlace.connect(owner).getItemBidsLength();257 expect(length).to.be.equal(1);258 });259 it('Should be able to accept bid on market item', async () => {260 const collectionTxn = await marketPlace.connect(owner).createCollection('image1', 'name2', 'description1');261 const collectionTx = await collectionTxn.wait();262 const collectionId = collectionTx.events[0].args.collectionId.toNumber();263 const tokenTxn = await marketPlace.connect(owner).mintToken('tokenURI', 'name', 'description', collectionId);264 const tokenTx = await tokenTxn.wait();265 const tokenId = tokenTx.events[1].args.tokenId.toNumber();266 const bidTxn = await marketPlace.connect(addr1).bidMarketItem(tokenId, { value: 1000 });267 const bidTx = await bidTxn.wait();268 const bidId = bidTx.events[0].args.bidId.toNumber();269 const approveTxn = await nft.connect(owner).approve(marketPlaceContractAddress, tokenId);270 await approveTxn.wait();271 const acceptTxn = await marketPlace.connect(owner).acceptBid(tokenId, bidId);272 await acceptTxn.wait();273 const newOwner = await nft.ownerOf(tokenId);274 expect(newOwner).to.be.equal(addr1.address);275 });276 it('Should fail if not owner nor approved', async () => {277 const collectionTxn = await marketPlace.connect(owner).createCollection('image1', 'name2', 'description1');278 const collectionTx = await collectionTxn.wait();279 const collectionId = collectionTx.events[0].args.collectionId.toNumber();280 const tokenTxn = await marketPlace.connect(owner).mintToken('tokenURI', 'name', 'description', collectionId);281 const tokenTx = await tokenTxn.wait();282 const tokenId = tokenTx.events[1].args.tokenId.toNumber();283 const bidTxn = await marketPlace.connect(addr1).bidMarketItem(tokenId, { value: 1000 });284 const bidTx = await bidTxn.wait();285 const bidId = bidTx.events[0].args.bidId.toNumber();286 await expect(marketPlace.connect(owner).acceptBid(tokenId, bidId)).to.be.revertedWith("ERC721: transfer caller is not owner nor approved");287 });288 it('Should fail to accept bid if bid does not exist', async () => {289 const collectionTxn = await marketPlace.connect(owner).createCollection('image1', 'name2', 'description1');290 const collectionTx = await collectionTxn.wait();291 const collectionId = collectionTx.events[0].args.collectionId.toNumber();292 const tokenTxn = await marketPlace.connect(owner).mintToken('tokenURI', 'name', 'description', collectionId);293 const tokenTx = await tokenTxn.wait();294 const tokenId = tokenTx.events[1].args.tokenId.toNumber();295 await expect(marketPlace.connect(owner).acceptBid(tokenId, 2)).to.be.revertedWith("Marketplace: no such bid");296 });297 it('Should be able to reject bid on market item', async () => {298 const collectionTxn = await marketPlace.connect(owner).createCollection('image1', 'name2', 'description1');299 const collectionTx = await collectionTxn.wait();300 const collectionId = collectionTx.events[0].args.collectionId.toNumber();301 const tokenTxn = await marketPlace.connect(owner).mintToken('tokenURI', 'name', 'description', collectionId);302 const tokenTx = await tokenTxn.wait();303 const tokenId = tokenTx.events[1].args.tokenId.toNumber();304 const bidTxn = await marketPlace.connect(addr1).bidMarketItem(tokenId, { value: 1000 });305 const bidTx = await bidTxn.wait();306 const bidId = bidTx.events[0].args.bidId.toNumber();307 const rejectTxn = await marketPlace.connect(owner).rejectBid(tokenId, bidId);308 await rejectTxn.wait();309 const lastOwner = await nft.ownerOf(tokenId);310 expect(lastOwner).to.be.equal(owner.address);311 });312 });313 it("Should increase the balance of the contract", async () => {314 await owner.sendTransaction({315 to: marketPlaceContractAddress,316 value: ethers.utils.parseEther("1.0")317 });318 const contractNewBalanceTxn = await marketPlace.connect(owner).getBalance();319 expect(contractNewBalanceTxn).to.equal(ethers.utils.parseEther("1.0"));320 })...

Full Screen

Full Screen

othertransactions.js

Source:othertransactions.js Github

copy

Full Screen

1$( document ).ready(function() {2});3function submitTxn() {4 let txnType = $("#type").val();5 let txnDate = $("#date").val();6 let txnDesc = $("#description").val();7 let txnAmt = $("#amount").val();8 if(txnType == "NA" || txnDesc == "" || txnAmt == "" || txnDate == "") {9 $("#modelMsg").html("Enter all mandatory inputs!!");10 $("#alertPopup").modal("show");11 return;12 }13 let confirmation = confirm("Are you sure to add the transaction??");14 if (confirmation == false) {15 return;16 }17 let otrTxnPayload = {};18 otrTxnPayload["date"] = txnDate;19 otrTxnPayload["bill_no"] = "NA";20 otrTxnPayload["description"] = txnDesc;21 if(txnType == "income") {22 otrTxnPayload["transaction_type"] = "Other Income";23 otrTxnPayload["income"] = txnAmt;24 otrTxnPayload["expense"] = 0;25 } else {26 otrTxnPayload["transaction_type"] = "Other Expense";27 otrTxnPayload["income"] = 0;28 otrTxnPayload["expense"] = txnAmt;29 }30 console.log("Calling transactions API..");31 genericApiCalls("POST", "/transactions", otrTxnPayload, otrTxnSuccesscb, errorcb);32 function otrTxnSuccesscb(data) {33 if(data["response"] == "transactions collection updated successfully!!") {34 $("#indexPgmodelMsg").html("Transaction updated successfully!!");35 setTimeout(function(){36 $("#indexPgRedirectionPopup").modal("show");37 }, 500);38 }39 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3var options = {4};5 if (err) return console.error(err);6 console.log('Test status:', data.statusText);7 if (data.statusCode == 200) {8 console.log('Test completed, check results at:', data.data.userUrl);9 }10});11var wpt = require('webpagetest');12var wpt = new WebPageTest('www.webpagetest.org');13var options = {14};15 console.log('Test status:', data.statusText);16 if (data.statusCode == 200) {17 console.log('Test completed, check results at:', data.data.userUrl);18 }19});20var wpt = require('webpagetest');21var wpt = new WebPageTest('www.webpagetest.org');22var options = {23};24console.log('Test status:', data.statusText);25if (data.statusCode == 200) {26 console.log('Test completed, check results at:', data.data.userUrl);27}28var wpt = require('webpagetest');29var wpt = new WebPageTest('www.webpagetest.org');30var options = {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3var options = {4};5wpt.runTest(options, function(err, data) {6 if (err) return console.log(err);7 console.log('Test submitted to WebPageTest for %s', data.data.url);8 console.log('View your test at %s', data.data.userUrl);9 wpt.getTestResults(data.data.testId, function(err, data) {10 if (err) return console.log(err);11 console.log('Test from %s completed on %s', data.data.from, data.data.completed);12 console.log('First View Speed Index: %s', data.data.average.firstView.SpeedIndex);13 });14});15wpt.runTest(options)16 .then(function(data) {17 console.log('Test submitted to WebPageTest for %s', data.data.url);18 console.log('View your test at %s', data.data.userUrl);19 return wpt.getTestResults(data.data.testId);20 })21 .then(function(data) {22 console.log('Test from %s completed on %s', data.data.from, data.data.completed);23 console.log('First View Speed Index: %s', data.data.average.firstView.SpeedIndex);24 })25 .catch(function(err) {26 console.log(err);27 });28var options = {

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful