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
22 changes: 22 additions & 0 deletions lib/order/__tests__/GenerateTransactionTypes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const withPlaceAssetTxns = require('../txns/sell/withPlaceAssetTxns');
const withPlaceAlgoTxns = require('../txns/buy/withPlaceAlgoTxns');
const withCloseAssetTxns = require('../txns/close/withCloseAssetTxns');
const withCloseAlgoTxns = require('../txns/close/withCloseAlgoTxns');

const compile = require('../compile/compile');
const AlgodexApi = require('../../AlgodexApi');

Expand Down Expand Up @@ -82,6 +84,26 @@ const TransactionGenerator = {
})
);
},
getCloseAlgoEscrowOrderTxns: async function (order, optIn) {
return await withCloseAlgoTxns(
await compile({
...order,
appId:
typeof order.appId === 'undefined'
? await algodexApi.getAppId(order)
: order.appId,
version: 6,
indexer: algodexApi.indexer,
contract: {
creator: order.address,
},
wallet: {
...order.wallet,
...(await algodexApi.http.indexer.fetchAccountInfo(order.wallet)),
},
})
);
},
};

module.exports = TransactionGenerator;
126 changes: 15 additions & 111 deletions lib/order/__tests__/TealAlgoEscrowPlaceNoOptInTxn.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,136 +9,40 @@ const accountSetup = require('./accountSetup.js');
const JEST_MINUTE_TIMEOUT = 60 * 1000;
const config = require('./TealConfig');
const { timeout } = require('../../teal/utils');
// const testHelper = require('./setup.js');
// const transactionGenerator = require('../generate_transaction_types.js');
// const createAppTest = require('./teal_tests/createAppTest.js');
// const deleteAppTest = require('./teal_tests/deleteAppTest.js');
// const placeOrderTest = require('./teal_tests/placeAlgoEscrowOrder.js');
// const executeAlgoOrderTest = require('./teal_tests/executeAlgoEscrowOrder.js');
// const executeAsaOrderTest = require('./teal_tests/executeASAEscrowOrder.js');
// const placeASAOrderTest = require('./teal_tests/placeASAEscrowOrder.js');
// const closeOrderTest = require('./teal_tests/closeAlgoEscrowOrder.js');
// const closeASAOrderTest = require('./teal_tests/closeASAEscrowOrder.js');
// const algosdk = require('algosdk');
//
//
// const AlgodexApi = require('../algodex_api.js');
// const constants = require('../constants.js');
// const JEST_MINUTE_TIMEOUT = 60 * 1000;
//
// const config = {
// appId: -1,
// creatorAccount: testHelper.getRandomAccount(),
// executorAccount: testHelper.getRandomAccount(),
// openAccount: testHelper.getOpenAccount(),
// maliciousAccount: testHelper.getRandomAccount(),
// client: testHelper.getLocalClient(),
// assetId: 66711302,
// };
//
// 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.
// const negTests = [
// /* {txnNum: 0, field: 'from', val: algosdk.decodeAddress(config.maliciousAccount.addr) },
// {txnNum: 0, field: 'appArgs', innerNum: 0, val: textEncoder.encode('execute') },
// {txnNum: 0, field: 'appIndex', configKeyForVal: 'fakeAppId' },
// {txnNum: 0, field: 'appOnComplete', val: 0},
// {txnNum: 1, field: 'from', val: algosdk.decodeAddress(config.maliciousAccount.addr) },
// {txnNum: 1, field: 'closeRemainderTo', val: algosdk.decodeAddress(config.maliciousAccount.addr) },
// {txnNum: 1, negTxn: {
// unsignedTxnPromise: transactionGenerator.getAssetSendTxn(config.client, config.maliciousAccount.addr, config.maliciousAccount.addr,
// 1000, config.assetId, false),
// senderAcct: config.maliciousAccount
// }
// },
// {txnNum: 2, field: 'from', txnKeyForVal: 'from', txnNumForVal: 1}, //set to from escrow
// {txnNum: 2, field: 'to', val: algosdk.decodeAddress(config.maliciousAccount.addr)},
// {txnNum: 2, negTxn: {
// unsignedTxnPromise: transactionGenerator.getPayTxn(config.client,
// config.maliciousAccount.addr, config.maliciousAccount.addr,
// 1000, false),
// senderAcct: config.maliciousAccount
// }
// },*/
//
// ];
//
describe.skip('ALGO ESCROW ORDER BOOK (opt in test)', () => {
const closeAlgoOrderTest = require('./teal_tests/closeAlgoEscrowOrder.js');
const accountCleanup = require('./accountCleanup.js');

describe('ALGO ESCROW ORDER BOOK (opt in test)', () => {
const amount = 0.8;
const price = 1.2;
beforeAll(async () => {
// await accountSetup(config, 'buy', true); //optIn in the setUp phase to test sdk no optIn
await accountSetup(config, 'buy', true); //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);

// 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
// );
// });
afterAll(async () => {
await timeout(4000);
await accountCleanup(config, 'buy', true);
}, JEST_MINUTE_TIMEOUT);

test(
'Place algo escrow order',
async () => {
// let asaBalance = await testHelper.getAssetBalance(
// config.creatorAccount.addr,
// config.assetId
// );
// expect(asaBalance).toBeGreaterThan(0); // already opted in and has ASA

const result = await placeAlgoOrderTest.runTest(config, 0.8, 1.2);
const result = await placeAlgoOrderTest.runTest(config, amount, price);
expect(result).toBeTruthy();

// asaBalance = await testHelper.getAssetBalance(
// config.creatorAccount.addr,
// config.assetId
// );
// expect(asaBalance).toBeGreaterThan(0);
await timeout(4000);
},
JEST_MINUTE_TIMEOUT
);

test(
'Close algo escrow order',
async () => {
const result = await closeOrderTest.runTest(config, 1.2);
await timeout(3000);
const result = await closeAlgoOrderTest.runTest(config, price, amount);
expect(result).toBeTruthy();
},
JEST_MINUTE_TIMEOUT
);

// test(
// 'Delete algo escrow order book',
// async () => {
// const result = await deleteAppTest.runTest(config);
// expect(result).toBeTruthy();
// },
// JEST_MINUTE_TIMEOUT
// );
});
//
109 changes: 18 additions & 91 deletions lib/order/__tests__/TealAlgoEscrowPlaceWithOptInTxn.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,110 +9,37 @@ const accountSetup = require('./accountSetup.js');
const JEST_MINUTE_TIMEOUT = 60 * 1000;
const config = require('./TealConfig');
const { timeout } = require('../../teal/utils');
const closeAlgoOrderTest = require('./teal_tests/closeAlgoEscrowOrder.js');
const accountCleanup = require('./accountCleanup.js');

//
// // TODO: The negative tests need to be implemented. The commented ones out are examples but will not work with
// // this transaction type.
// const negTests = [
// /* {txnNum: 0, field: 'from', val: algosdk.decodeAddress(config.maliciousAccount.addr) },
// {txnNum: 0, field: 'appArgs', innerNum: 0, val: textEncoder.encode('execute') },
// {txnNum: 0, field: 'appIndex', configKeyForVal: 'fakeAppId' },
// {txnNum: 0, field: 'appOnComplete', val: 0},
// {txnNum: 1, field: 'from', val: algosdk.decodeAddress(config.maliciousAccount.addr) },
// {txnNum: 1, field: 'closeRemainderTo', val: algosdk.decodeAddress(config.maliciousAccount.addr) },
// {txnNum: 1, negTxn: {
// unsignedTxnPromise: transactionGenerator.getAssetSendTxn(config.client, config.maliciousAccount.addr, config.maliciousAccount.addr,
// 1000, config.assetId, false),
// senderAcct: config.maliciousAccount
// }
// },
// {txnNum: 2, field: 'from', txnKeyForVal: 'from', txnNumForVal: 1}, //set to from escrow
// {txnNum: 2, field: 'to', val: algosdk.decodeAddress(config.maliciousAccount.addr)},
// {txnNum: 2, negTxn: {
// unsignedTxnPromise: transactionGenerator.getPayTxn(config.client,
// config.maliciousAccount.addr, config.maliciousAccount.addr,
// 1000, false),
// senderAcct: config.maliciousAccount
// }
// },*/
//
// ];
//
describe.skip('ALGO ESCROW ORDER BOOK (opt in test)', () => {
describe('ALGO ESCROW ORDER BOOK (opt in test)', () => {
const amount = 0.8;
const price = 1.2;
beforeAll(async () => {
await accountSetup(config, 'buy', false);
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 algo escrow order book', async () => {
// config.appId = await createAppTest.runTest(config, true);
// config.fakeAppId = await createAppTest.createFakeApp(config);
// global.ALGO_ESCROW_APP_ID = config.appId;
// expect(config.appId).toBeGreaterThan(0);
// config.oldCreatorAccount = config.creatorAccount;
// // make a new creatorAccount that hasn't been opted into any ASA
// config.creatorAccount = testHelper.getRandomAccount();
// testHelper.transferFunds(config.client, config.openAccount, config.creatorAccount, 2000000);
// testHelper.transferFunds(config.client, config.openAccount, config.maliciousAccount, 2000000);
// }, 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);
// });
afterAll(async () => {
await timeout(4000);
await accountCleanup(config, 'buy', false);
}, JEST_MINUTE_TIMEOUT);

test(
'Place algo escrow order',
async () => {
// let asaBalance = await testHelper.getAssetBalance(
// config.creatorAccount.addr,
// config.assetId
// );
// expect(asaBalance).toBeNull();

const result = await placeAlgoOrderTest.runTest(config, 0.8, 1.2);
const result = await placeAlgoOrderTest.runTest(config, amount, price);
expect(result).toBeTruthy();

// asaBalance = await testHelper.getAssetBalance(
// config.creatorAccount.addr,
// config.assetId
// );
// expect(asaBalance).toEqual(0);
},
JEST_MINUTE_TIMEOUT
);

// test(
// 'Close algo escrow order',
// async () => {
// const result = await closeOrderTest.runTest(config, 1.2);
// expect(result).toBeTruthy();
// },
// JEST_MINUTE_TIMEOUT
// );

// test(
// 'Delete algo escrow order book',
// async () => {
// await testHelper.closeAccount(
// config.client,
// config.creatorAccount,
// config.openAccount
// );
// config.creatorAccount = config.oldCreatorAccount;
// const result = await deleteAppTest.runTest(config);
// expect(result).toBeTruthy();
// },
// JEST_MINUTE_TIMEOUT
// );
test(
'Close algo escrow order',
async () => {
const result = await closeAlgoOrderTest.runTest(config, price, amount);
expect(result).toBeTruthy();
},
JEST_MINUTE_TIMEOUT
);
});
9 changes: 3 additions & 6 deletions lib/order/__tests__/accountCleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@ async function cleanupAccounts(
await transferFunds(client, creatorAccount, openAccount, 1500000); //transfer original algo
}

// if (type === "buy") {
// await transferFunds(client, openAccount, creatorAccount, 5000000); //enough funds to facilitate an escrow place
// if (optIn) {
// await transferASA(client, creatorAccount, creatorAccount, 0, assetId); // opt in transaction
// }
// }
if (type === 'buy') {
await transferFunds(client, creatorAccount, openAccount, 1750000); //transfer original algo
}

// if (optIn) {
// await transferASA(client, executorAccount, executorAccount, 0, config.assetIndex); // opt in transaction
Expand Down
Loading