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
66 changes: 66 additions & 0 deletions lib/order/__tests__/GenerateTransactionTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const withPlaceAssetTxns = require('../txns/sell/withPlaceAssetTxns');
const makePlaceAlgoTxns = require('../txns/buy/makePlaceAlgoTxns');
const compile = require('../compile/compile');
const AlgodexApi = require('../../AlgodexApi');

const tesnet = {
config: {
algod: {
uri: 'https://node.testnet.algoexplorerapi.io',
token: '',
},
indexer: {
uri: 'https://algoindexer.testnet.algoexplorerapi.io',
token: '',
},
explorer: {
uri: 'https://indexer.testnet.algoexplorerapi.io',
port: '',
},
dexd: {
uri: 'https://api-testnet-public.algodex.com/algodex-backend',
token: '',
},
},
};

const algodexApi = new AlgodexApi(tesnet);

const TransactionGenerator = {
getPlaceASAEscrowOrderTxns: async function (order, optIn) {
return await withPlaceAssetTxns(
await compile({
...order,
appId:
typeof order.appId === 'undefined'
? await algodexApi.getAppId(order)
: order.appId,
version: 6,
indexer: algodexApi.indexer,
wallet: {
...order.wallet,
...(await algodexApi.http.indexer.fetchAccountInfo(order.wallet)),
},
})
);
},
getPlaceAlgoEscrowOrderTxns: async function (order, optIn) {
return await makePlaceAlgoTxns(
await compile({
...order,
appId:
typeof order.appId === 'undefined'
? await algodexApi.getAppId(order)
: order.appId,
version: 6,
indexer: algodexApi.indexer,
wallet: {
...order.wallet,
...(await algodexApi.http.indexer.fetchAccountInfo(order.wallet)),
},
})
);
},
};

module.exports = TransactionGenerator;
123 changes: 76 additions & 47 deletions lib/order/__tests__/TealAsaEscrowPlace.spec.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
it('should fix these tests', ()=>{
it('should fix these tests', () => {
const isBroken = true;
expect(isBroken).toEqual(true);
});
const testHelper = require('./setup.js');
const createAppTest = require('./teal_tests/createAppTest.js');
const deleteAppTest = require('./teal_tests/deleteAppTest.js');
const executeAlgoOrderTest = require('./teal_tests/executeAlgoEscrowOrder.js');
const connector = require('../../wallet/connectors/AlgoSDK');

// const deleteAppTest = require('./teal_tests/deleteAppTest.js');

const placeASAOrderTest = require('./teal_tests/placeASAEscrowOrder.js');
const closeASAOrderTest = require('./teal_tests/closeASAEscrowOrder.js');
// const closeASAOrderTest = require('./teal_tests/closeASAEscrowOrder.js');
const constants = require('./constants.js');
const setup = require('./beforeAll.js');
const JEST_MINUTE_TIMEOUT = 60 * 1000;

const config = {
Expand All @@ -18,12 +20,15 @@ const config = {
openAccount: testHelper.getOpenAccount(),
maliciousAccount: testHelper.getRandomAccount(),
client: testHelper.getLocalClient(),
connector: connector,
assetId: 66711302,
};

console.log('DEBUG_SMART_CONTRACT_SOURCE is: ' + constants.DEBUG_SMART_CONTRACT_SOURCE);
console.log(
'DEBUG_SMART_CONTRACT_SOURCE is: ' + constants.DEBUG_SMART_CONTRACT_SOURCE
);


const textEncoder = new TextEncoder();
//
// // TODO: The negative tests need to be implemented. The commented ones out are examples but will not work with
// // this transaction type.
Expand Down Expand Up @@ -54,48 +59,72 @@ const textEncoder = new TextEncoder();
//
//
describe('ASA ESCROW ORDER BOOK', () => {
test('Create asa escrow order book', async () => {
config.creatorAccount = testHelper.getRandomAccount();
config.executorAccount = testHelper.getRandomAccount();
config.maliciousAccount = testHelper.getRandomAccount();
config.appId = await createAppTest.runTest(config, false);
global.ASA_ESCROW_APP_ID = config.appId;
expect(config.appId).toBeGreaterThan(0);
function timeout(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
beforeAll(async () => {
await setup(config, 'sell', true)
await timeout(7000) // Eliminates race condition where future indexer calls occur before setUp step fully propogates but after it succeeds

}, JEST_MINUTE_TIMEOUT);
// test(
// 'Create asa escrow order book',
// async () => {
// config.creatorAccount = testHelper.getRandomAccount();
// config.executorAccount = testHelper.getRandomAccount();
// config.maliciousAccount = testHelper.getRandomAccount();
// config.appId = await createAppTest.runTest(config, false);
// global.ASA_ESCROW_APP_ID = config.appId;
// expect(config.appId).toBeGreaterThan(0);
// },
// JEST_MINUTE_TIMEOUT,
// );

test('Place asa escrow order', async () => {
const asaAmount = 400000;
const price = 1.25;
const result = await placeASAOrderTest.runTest(config, asaAmount, price);
expect(result).toBeTruthy();
}, JEST_MINUTE_TIMEOUT);
//
// negTests.map( (negTestTxnConfig) => {
// const testName = `Negative algo full execution order test: txnNum: ${negTestTxnConfig.txnNum} field: ${negTestTxnConfig.field} val: ${negTestTxnConfig.val}`;
// test(testName, async () => {
// if (negTestTxnConfig.negTxn) {
// negTestTxnConfig.negTxn.unsignedTxn = await negTestTxnConfig.negTxn.unsignedTxnPromise;
// }
// const outerTxns = await executeAlgoOrderTest.runFullExecTest(config, true);
// outerTxns.map( (txn) => {
// const unsignedTxn = txn.unsignedTxn;
// // console.log({unsignedTxn});
// });
// const result = await testHelper.runNegativeTest(config, config.client, outerTxns, negTestTxnConfig);
// expect(result).toBeTruthy();
// }, JEST_MINUTE_TIMEOUT);
// });
//
//
test('Close asa escrow order', async () => {
const price = 1.25;
const result = await closeASAOrderTest.runTest(config, price);
expect(result).toBeTruthy();
}, JEST_MINUTE_TIMEOUT);
test(
'Place asa escrow order',
async () => {
const asaAmount = 0.4;
const price = 1.25;
const result = await placeASAOrderTest.runTest(config, asaAmount, price);
expect(result).toBeTruthy();
},
JEST_MINUTE_TIMEOUT
);
//
// negTests.map( (negTestTxnConfig) => {
// const testName = `Negative algo full execution order test: txnNum: ${negTestTxnConfig.txnNum} field: ${negTestTxnConfig.field} val: ${negTestTxnConfig.val}`;
// test(testName, async () => {
// if (negTestTxnConfig.negTxn) {
// negTestTxnConfig.negTxn.unsignedTxn = await negTestTxnConfig.negTxn.unsignedTxnPromise;
// }
// const outerTxns = await executeAlgoOrderTest.runFullExecTest(config, true);
// outerTxns.map( (txn) => {
// const unsignedTxn = txn.unsignedTxn;
// // console.log({unsignedTxn});
// });
// const result = await testHelper.runNegativeTest(config, config.client, outerTxns, negTestTxnConfig);
// expect(result).toBeTruthy();
// }, JEST_MINUTE_TIMEOUT);
// });
//
//
// test(
// 'Close asa escrow order',
// async () => {
// const price = 1.25;
// const result = await closeASAOrderTest.runTest(config, price);
// expect(result).toBeTruthy();
// },
// JEST_MINUTE_TIMEOUT
// );

test('Delete asa escrow order book', async () => {
const result = await deleteAppTest.runTest(config);
expect(result).toBeTruthy();
}, JEST_MINUTE_TIMEOUT);
// test(
// 'Delete asa escrow order book',
// async () => {
// const result = await deleteAppTest.runTest(config);
// expect(result).toBeTruthy();
// },
// JEST_MINUTE_TIMEOUT
// );
});
//
29 changes: 14 additions & 15 deletions lib/order/__tests__/asa_dex_teal.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/////////////////////////////
// ///////////////////////////
// Alexander Trefonas //
// 7/9/2021 //
// Copyright Algodev Inc //
// All Rights Reserved. //
/////////////////////////////
// ///////////////////////////

const AsaOrderbookTeal = {

getClearProgram : function getClearProgram() {
const clearProgram =
getClearProgram: function getClearProgram() {
const clearProgram =
`
#pragma version 2
// This program clears program state.
Expand All @@ -19,12 +19,12 @@ const AsaOrderbookTeal = {
`
;
return clearProgram;
},
getASAOrderBookApprovalProgram : function getASAOrderBookApprovalProgram() {
// stateful DEX contract
// This is for the order book
return `
},

getASAOrderBookApprovalProgram: function getASAOrderBookApprovalProgram() {
// stateful DEX contract
// This is for the order book
return `
////////////////////////////////////////////////
// STATEFUL CONTRACT /
// ORDER BOOK FOR ASA ESCROWS (SELL ORDERS) /
Expand Down Expand Up @@ -327,8 +327,7 @@ const AsaOrderbookTeal = {


`;

}
};

module.exports = AsaOrderbookTeal;
},
};

module.exports = AsaOrderbookTeal;
36 changes: 20 additions & 16 deletions lib/order/__tests__/beforeAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ const AlgodexApi = require('../../AlgodexApi');
const apiConfig = require('../../../config.json');
const initAccounts = require('../../teal/test/initAccounts');
const logger = require('../../logger');



/**
*
* @param {TestConfig} config Test Configuration
Expand All @@ -19,31 +22,32 @@ async function beforeAll(config, type, optIn = false, newCreator = false) {
}

// Initalize API Client
await config.init(AlgodexApi, [apiConfig]);
// await config.init(AlgodexApi, [apiConfig]);
const api = new AlgodexApi(apiConfig)

// Initialize Accounts and Configuration
await initAccounts(config, optIn, newCreator);

const {client, creatorAccount} = config;
const createTxn = await txns.makeApplicationCreateTxn(
client,
type,
creatorAccount,
config.suggestedParams,
);
const txId = createTxn.txID().toString();
// const {client, creatorAccount} = config;
// const createTxn = await txns.makeApplicationCreateTxn(
// client,
// type,
// creatorAccount,
// config.suggestedParams,
// );
// const txId = createTxn.txID().toString();

const signedTxn = createTxn.signTxn(creatorAccount.sk);
// const signedTxn = createTxn.signTxn(creatorAccount.sk);

await client.sendRawTransaction(signedTxn).do();
// await client.sendRawTransaction(signedTxn).do();

// Wait for confirmation
await algosdk.waitForConfirmation(client, txId, 10);
// // Wait for confirmation
// await algosdk.waitForConfirmation(client, txId, 10);

// display results
const transactionResponse = await client.pendingTransactionInformation(txId).do();
// // display results
// const transactionResponse = await client.pendingTransactionInformation(txId).do();

config.setAppIndex(transactionResponse['application-index']);
// config.setAppIndex(transactionResponse['application-index']);
}

module.exports = beforeAll;
Loading