Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions lib/order/__tests__/DestroyAsset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const algosdk = require('algosdk');
const ALGOD_SERVER = 'https://node.testnet.algoexplorerapi.io';
const ALGOD_TOKEN = ''; // { 'X-API-Key': 'VELyABA1dGqGbAVktbew4oACvp0c0298gMgYtYIb' }
const ALGOD_PORT = '';

const client = new algosdk.Algodv2(
ALGOD_TOKEN,
ALGOD_SERVER,
ALGOD_PORT,
);
/**
*
* @param {object} assetCreator
* @param {string} assetId
* @return {Promise<void>}
*/
async function destroyAsset(assetCreator, assetId) {
const params = await client.getTransactionParams().do();

const dtxn = algosdk.makeAssetDestroyTxnWithSuggestedParams(
assetCreator.addr,
undefined,
assetId,
params);

const rawSignedTxn = dtxn.signTxn(assetCreator.sk);
const txn = (await client.sendRawTransaction(rawSignedTxn).do());
const confirmedTxn = await algosdk.waitForConfirmation(client, txn.txId, 4);
console.log(confirmedTxn);

console.log('asset destroyed');
}

module.exports = destroyAsset;

60 changes: 60 additions & 0 deletions lib/order/__tests__/GenerateAsset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const algosdk = require('algosdk');
const ALGOD_SERVER = 'https://node.testnet.algoexplorerapi.io';
const ALGOD_TOKEN = ''; // { 'X-API-Key': 'VELyABA1dGqGbAVktbew4oACvp0c0298gMgYtYIb' }
const ALGOD_PORT = '';

const client = new algosdk.Algodv2(
ALGOD_TOKEN,
ALGOD_SERVER,
ALGOD_PORT,
);
/**
*
* @param {number} length
* @return {String}
*/
function makeid(length) {
let result = '';
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const charactersLength = characters.length;
for ( let i = 0; i < length; i++ ) {
result += characters.charAt(Math.floor(Math.random() *
charactersLength));
}
return result;
}
/**
*
* @param {object} assetCreator
* @param {number} decimals
* @return {Promise<void>}
*/
async function generateAsset(assetCreator, decimals=6) {
const params = await client.getTransactionParams().do();

const createAssetTxn = algosdk.makeAssetCreateTxnWithSuggestedParams(
assetCreator.addr,
undefined, // no note for time being
10000000, // hardCoded issuance for time being
decimals, // hardCoded decimals for time
false,
assetCreator.addr,
undefined,
assetCreator.addr,
assetCreator.addr,
makeid(7),
makeid(7),
undefined,
undefined,
params);

const rawSignedTxn = createAssetTxn.signTxn(assetCreator.sk);
const txn = (await client.sendRawTransaction(rawSignedTxn).do());
const ptx = await algosdk.waitForConfirmation(client, txn.txId, 4);
const assetId = ptx['asset-index'];

return assetId;
}

module.exports = generateAsset;

34 changes: 25 additions & 9 deletions lib/order/__tests__/TealAlgoEscrowCancel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,40 @@ const placeAlgoOrderTest = require('./teal_tests/placeAlgoEscrowOrder.js');
const closeAlgoOrderTest = require('./teal_tests/closeAlgoEscrowOrder.js');
const JEST_MINUTE_TIMEOUT = 60 * 1000;
const accountSetup = require('./accountSetup.js');
const accountCleanup = require('./accountCleanup');
const generateAsset = require('./GenerateAsset');
const destroyAsset = require('./DestroyAsset');

describe('ALGO ESCROW CANCEL', () => {

describe(`ALGO ESCROW CANCEL`, () => {
const price = 1.2;
const amount = 0.8;
const note = `
Testing: TealAlgoEscrowCancel
Open Account: ${config.openAccount.addr}
Creator Account: ${config.creatorAccount.addr}

Creator Account is buying ${amount} LAMPC at price: ${price} Algo
`;

beforeAll(async () => {
const assetId = await generateAsset(config.openAccount);
console.log(assetId);

const note = `
Testing: TealAlgoEscrowCancel
assetId: ${assetId}
Open Account: ${config.openAccount.addr}
Creator Account: ${config.creatorAccount.addr}

Creator Account is buying ${amount} LAMPC at price: ${price} Algo
`;
config.assetId = assetId;

await accountSetup(config, 'buy', true, false, note);
await timeout(7000); // Eliminates race condition where future indexer calls occur before setUp step fully propogates but after it succeeds
}, JEST_MINUTE_TIMEOUT);

// Create App
afterAll(async () => {
await timeout(4000);
await accountCleanup(config, 'buy', true);
await destroyAsset(config.openAccount, config.assetId);
}, JEST_MINUTE_TIMEOUT);


test(
'Place Algo Escrow Order',
async () => {
Expand Down
27 changes: 17 additions & 10 deletions lib/order/__tests__/TealAlgoEscrowPayCloseout.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,38 @@ const executeAlgoEscrowOrderTest = require('./teal_tests/executeAlgoEscrowOrder'
const JEST_MINUTE_TIMEOUT = 60 * 1000;
const config = require('./TealConfig');
const takerAccountCleanup = require('./takerAccountCleanup');
const generateAsset = require('./GenerateAsset');
const destroyAsset = require('./DestroyAsset');

//
describe('Algo ESCROW PAY CLOSEOUT', () => {
const asaAmount = 0.4;
const price = 1.25;
const executorAmount = 0.4;

const note = `
Testing: TealAlgoEscrowPayCloseout
Open Account: ${config.openAccount.addr}
Creator Account: ${config.creatorAccount.addr}
Executor Account: ${config.executorAccount.addr}

Creator Account is buying ${asaAmount} LAMPC at price: ${price} Algo
Executor Account is selling ${executorAmount} LAMPC
`;

beforeAll(async () => {
const assetId = await generateAsset(config.openAccount);
console.log(assetId);

const note = `
Testing: TealAlgoEscrowPayCloseout
assetId: ${assetId}
Open Account: ${config.openAccount.addr}
Creator Account: ${config.creatorAccount.addr}

Creator Account is buying ${asaAmount} LAMPC at price: ${price} Algo
Executor Account is selling ${executorAmount} LAMPC
`;
config.assetId = assetId;
await accountSetup(config, 'buy', true, true, note);
await timeout(7000); // Eliminates race condition where future indexer calls occur before setUp step fully propogates but after it succeeds
}, JEST_MINUTE_TIMEOUT);
}, JEST_MINUTE_TIMEOUT*3);

afterAll(async () => {
await timeout(4000);
await takerAccountCleanup(config, 'buy', executorAmount, true);
await destroyAsset(config.openAccount, config.assetId);
}, JEST_MINUTE_TIMEOUT);

test(
Expand Down
12 changes: 10 additions & 2 deletions lib/order/__tests__/TealAlgoEscrowPayPartial.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,40 @@ const executeAlgoEscrowOrderTest = require('./teal_tests/executeAlgoEscrowOrder'
const JEST_MINUTE_TIMEOUT = 60 * 1000;
const config = require('./TealConfig');
const takerAccountCleanup = require('./takerAccountCleanup');
const generateAsset = require('./GenerateAsset');
const destroyAsset = require('./DestroyAsset');

//
describe('Algo ESCROW PAY PARTIAL', () => {
const asaAmount = 0.4;
const price = 1.25;
const executorAmount = 0.2;

beforeAll(async () => {
const assetId = await generateAsset(config.openAccount);
console.log(assetId);

const note = `
const note = `
Testing: TealAlgoEscrowPayPartial
assetId: ${assetId}
Open Account: ${config.openAccount.addr}
Creator Account: ${config.creatorAccount.addr}
Executor Account: ${config.executorAccount.addr}

Creator Account is buying ${asaAmount} LAMPC at price: ${price} Algo
Executor Account is selling ${executorAmount} LAMPC
`;
config.assetId = assetId;


beforeAll(async () => {
await accountSetup(config, 'buy', true, true, note);
await timeout(7000); // Eliminates race condition where future indexer calls occur before setUp step fully propogates but after it succeeds
}, JEST_MINUTE_TIMEOUT);

afterAll(async () => {
await timeout(4000);
await takerAccountCleanup(config, 'buy', executorAmount);
await destroyAsset(config.openAccount, config.assetId);
}, JEST_MINUTE_TIMEOUT);

test(
Expand Down
21 changes: 15 additions & 6 deletions lib/order/__tests__/TealAlgoEscrowPlaceNoOptInTxn.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,35 @@ const config = require('./TealConfig');
const {timeout} = require('../../teal/utils');
const closeAlgoOrderTest = require('./teal_tests/closeAlgoEscrowOrder.js');
const accountCleanup = require('./accountCleanup.js');
const generateAsset = require('./GenerateAsset');
const destroyAsset = require('./DestroyAsset');

describe('ALGO ESCROW PLACE NO OPT IN TXN', () => {
const amount = 0.8;
const price = 1.2;

const note = `
Testing: TealAlgoEscrowPlaceNoOptInTxn
Open Account: ${config.openAccount.addr}
Creator Account: ${config.creatorAccount.addr}

Creator Account is buying ${amount} LAMPC at price: ${price} Algo
`;
beforeAll(async () => {
const assetId = await generateAsset(config.openAccount);
console.log(assetId);
const note = `
Testing: TealAlgoEscrowPlaceNoOptInTxn
assetId: ${assetId}

Open Account: ${config.openAccount.addr}
Creator Account: ${config.creatorAccount.addr}

Creator Account is buying ${amount} LAMPC at price: ${price} Algo
`;
config.assetId = assetId;
await accountSetup(config, 'buy', true, false, note); // optIn in the setUp phase to test sdk no optIn
await timeout(7000); // Eliminates race condition where future indexer calls occur before setUp step fully propogates but after it succeeds
}, JEST_MINUTE_TIMEOUT);

afterAll(async () => {
await timeout(4000);
await accountCleanup(config, 'buy', true);
await destroyAsset(config.openAccount, config.assetId);
}, JEST_MINUTE_TIMEOUT);

test(
Expand Down
15 changes: 12 additions & 3 deletions lib/order/__tests__/TealAlgoEscrowPlaceWithOptInTxn.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,36 @@ const config = require('./TealConfig');
const {timeout} = require('../../teal/utils');
const closeAlgoOrderTest = require('./teal_tests/closeAlgoEscrowOrder.js');
const accountCleanup = require('./accountCleanup.js');
const generateAsset = require('./GenerateAsset');
const destroyAsset = require('./DestroyAsset');

describe('ALGO ESCROW PLACE WITH OPT IN TXN', () => {
const amount = 0.8;
const price = 1.2;

const note = `
beforeAll(async () => {
const assetId = await generateAsset(config.openAccount);
console.log(assetId);

const note = `
Testing: TealAlgoEscrowPlaceWithOptInTxn
assetId: ${assetId}

Open Account: ${config.openAccount.addr}
Creator Account: ${config.creatorAccount.addr}

Creator Account is buying ${amount} LAMPC at price: ${price} Algo
`;
config.assetId = assetId;

beforeAll(async () => {
await accountSetup(config, 'buy', false, false, note);
await timeout(7000); // Eliminates race condition where future indexer calls occur before setUp step fully propogates but after it succeeds
await timeout(10000); // Eliminates race condition where future indexer calls occur before setUp step fully propogates but after it succeeds
}, JEST_MINUTE_TIMEOUT);

afterAll(async () => {
await timeout(4000);
await accountCleanup(config, 'buy', false);
await destroyAsset(config.openAccount, config.assetId);
}, JEST_MINUTE_TIMEOUT);

test(
Expand Down
33 changes: 24 additions & 9 deletions lib/order/__tests__/TealAsaEscrowCancel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,42 @@ const closeASAOrderTest = require('./teal_tests/closeASAEscrowOrder.js');
const JEST_MINUTE_TIMEOUT = 60 * 1000;
const placeASAOrderTest = require('./teal_tests/placeASAEscrowOrder.js');
const accountSetup = require('./accountSetup.js');
const accountCleanup = require('./accountCleanup');
const generateAsset = require('./GenerateAsset');
const destroyAsset = require('./DestroyAsset');


describe('ASA ESCROW CANCEL', () => {
const price = 1.2;
const amount = 0.8;
const note = `
Testing: TealAsaEscrowCancel
Open Account: ${config.openAccount.addr}
Creator Account: ${config.creatorAccount.addr}

Creator Account is buying ${amount} LAMPC at price: ${price} Algo
`;


// Create App
beforeAll(async () => {
// await accountSetup(config, "close")
await accountSetup(config, 'sell', true, true, note);
const assetId = await generateAsset(config.openAccount);
console.log(assetId);

const note = `
Testing: TealAsaEscrowCancel
assetId: ${assetId}

Open Account: ${config.openAccount.addr}
Creator Account: ${config.creatorAccount.addr}

Creator Account is buying ${amount} LAMPC at price: ${price} Algo
`;
config.assetId = assetId;

await accountSetup(config, 'sell', true, true, note);
await timeout(7000);
}, JEST_MINUTE_TIMEOUT * 10);

afterAll(async () => {
await timeout(4000);
await accountCleanup(config, 'sell', true);
await destroyAsset(config.openAccount, config.assetId);
}, JEST_MINUTE_TIMEOUT);

test(
'Place asa escrow order',
async () => {
Expand Down
Loading