Changeset View
Changeset View
Standalone View
Standalone View
apps/alias-server/test/aliasTests.js
// Copyright (c) 2023 The Bitcoin developers | // Copyright (c) 2023 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
'use strict'; | 'use strict'; | ||||
const assert = require('assert'); | const assert = require('assert'); | ||||
const cashaddr = require('ecashaddrjs'); | |||||
const config = require('../config'); | const config = require('../config'); | ||||
const { | const { | ||||
parseAliasTx, | parseAliasTx, | ||||
getAliasTxs, | getAliasTxs, | ||||
sortAliasTxsByTxidAndBlockheight, | sortAliasTxsByTxidAndBlockheight, | ||||
registerAliases, | registerAliases, | ||||
} = require('../src/alias'); | } = require('../src/alias'); | ||||
const { | const { removeUnconfirmedTxsFromTxHistory } = require('../src/utils'); | ||||
getOutputScriptFromAddress, | |||||
removeUnconfirmedTxsFromTxHistory, | |||||
} = require('../src/utils'); | |||||
const { | const { | ||||
testAddressAliases, | testAddressAliases, | ||||
testAddressAliasesWithUnconfirmedTxs, | testAddressAliasesWithUnconfirmedTxs, | ||||
aliases_fake_data, | aliases_fake_data, | ||||
} = require('./mocks/aliasMocks'); | } = require('./mocks/aliasMocks'); | ||||
// Mock mongodb | // Mock mongodb | ||||
const { MongoClient } = require('mongodb'); | const { MongoClient } = require('mongodb'); | ||||
const { MongoMemoryServer } = require('mongodb-memory-server'); | const { MongoMemoryServer } = require('mongodb-memory-server'); | ||||
Show All 9 Lines | describe('alias-server alias.js', async function () { | ||||
}); | }); | ||||
after(async () => { | after(async () => { | ||||
// Shut down mongo memory server after running this suite of unit tests | // Shut down mongo memory server after running this suite of unit tests | ||||
await testMongoClient.close(); | await testMongoClient.close(); | ||||
await mongoServer.stop(); | await mongoServer.stop(); | ||||
}); | }); | ||||
it('Correctly parses a 5-character alias transaction', function () { | it('Correctly parses a 5-character alias transaction', function () { | ||||
const registrationOutputScript = getOutputScriptFromAddress( | const registrationOutputScript = cashaddr.getOutputScriptFromAddress( | ||||
config.aliasConstants.registrationAddress, | config.aliasConstants.registrationAddress, | ||||
); | ); | ||||
assert.deepEqual( | assert.deepEqual( | ||||
parseAliasTx( | parseAliasTx( | ||||
testAddressAliases.txHistory[ | testAddressAliases.txHistory[ | ||||
testAddressAliases.txHistory.findIndex( | testAddressAliases.txHistory.findIndex( | ||||
i => | i => | ||||
i.txid === | i.txid === | ||||
'9d9fd465f56a7946c48b2e214386b51d7968a3a40d46cc697036e4fc1cc644df', | '9d9fd465f56a7946c48b2e214386b51d7968a3a40d46cc697036e4fc1cc644df', | ||||
) | ) | ||||
], | ], | ||||
config.aliasConstants, | config.aliasConstants, | ||||
registrationOutputScript, | registrationOutputScript, | ||||
), | ), | ||||
testAddressAliases.allAliasTxs[ | testAddressAliases.allAliasTxs[ | ||||
testAddressAliases.allAliasTxs.findIndex( | testAddressAliases.allAliasTxs.findIndex( | ||||
i => | i => | ||||
i.txid === | i.txid === | ||||
'9d9fd465f56a7946c48b2e214386b51d7968a3a40d46cc697036e4fc1cc644df', | '9d9fd465f56a7946c48b2e214386b51d7968a3a40d46cc697036e4fc1cc644df', | ||||
) | ) | ||||
], | ], | ||||
); | ); | ||||
}); | }); | ||||
it('Correctly parses a 6-character alias transaction', function () { | it('Correctly parses a 6-character alias transaction', function () { | ||||
const registrationOutputScript = getOutputScriptFromAddress( | const registrationOutputScript = cashaddr.getOutputScriptFromAddress( | ||||
config.aliasConstants.registrationAddress, | config.aliasConstants.registrationAddress, | ||||
); | ); | ||||
assert.deepEqual( | assert.deepEqual( | ||||
parseAliasTx( | parseAliasTx( | ||||
testAddressAliases.txHistory[ | testAddressAliases.txHistory[ | ||||
testAddressAliases.txHistory.findIndex( | testAddressAliases.txHistory.findIndex( | ||||
i => | i => | ||||
i.txid === | i.txid === | ||||
'36fdab59d25625b6ff3661aa5ab22a4893698fa5618e5e958e1d75bf921e6107', | '36fdab59d25625b6ff3661aa5ab22a4893698fa5618e5e958e1d75bf921e6107', | ||||
) | ) | ||||
], | ], | ||||
config.aliasConstants, | config.aliasConstants, | ||||
registrationOutputScript, | registrationOutputScript, | ||||
), | ), | ||||
testAddressAliases.allAliasTxs[ | testAddressAliases.allAliasTxs[ | ||||
testAddressAliases.allAliasTxs.findIndex( | testAddressAliases.allAliasTxs.findIndex( | ||||
i => | i => | ||||
i.txid === | i.txid === | ||||
'36fdab59d25625b6ff3661aa5ab22a4893698fa5618e5e958e1d75bf921e6107', | '36fdab59d25625b6ff3661aa5ab22a4893698fa5618e5e958e1d75bf921e6107', | ||||
) | ) | ||||
], | ], | ||||
); | ); | ||||
}); | }); | ||||
it('Returns false for an eToken transaction', function () { | it('Returns false for an eToken transaction', function () { | ||||
const registrationOutputScript = getOutputScriptFromAddress( | const registrationOutputScript = cashaddr.getOutputScriptFromAddress( | ||||
config.aliasConstants.registrationAddress, | config.aliasConstants.registrationAddress, | ||||
); | ); | ||||
assert.deepEqual( | assert.deepEqual( | ||||
parseAliasTx( | parseAliasTx( | ||||
testAddressAliases.txHistory[ | testAddressAliases.txHistory[ | ||||
testAddressAliases.txHistory.findIndex( | testAddressAliases.txHistory.findIndex( | ||||
i => | i => | ||||
i.txid === | i.txid === | ||||
'feafd053d4166601d42949a768b9c3e8ee1f27912fc84b6190aeb022fba7fa39', | 'feafd053d4166601d42949a768b9c3e8ee1f27912fc84b6190aeb022fba7fa39', | ||||
) | ) | ||||
], | ], | ||||
config.aliasConstants, | config.aliasConstants, | ||||
registrationOutputScript, | registrationOutputScript, | ||||
), | ), | ||||
false, | false, | ||||
); | ); | ||||
}); | }); | ||||
it('Returns false for a standard tx without an OP_RETURN', function () { | it('Returns false for a standard tx without an OP_RETURN', function () { | ||||
const registrationOutputScript = getOutputScriptFromAddress( | const registrationOutputScript = cashaddr.getOutputScriptFromAddress( | ||||
config.aliasConstants.registrationAddress, | config.aliasConstants.registrationAddress, | ||||
); | ); | ||||
assert.deepEqual( | assert.deepEqual( | ||||
parseAliasTx( | parseAliasTx( | ||||
testAddressAliases.txHistory[ | testAddressAliases.txHistory[ | ||||
testAddressAliases.txHistory.findIndex( | testAddressAliases.txHistory.findIndex( | ||||
i => | i => | ||||
i.txid === | i.txid === | ||||
▲ Show 20 Lines • Show All 136 Lines • Show Last 20 Lines |