Changeset View
Changeset View
Standalone View
Standalone View
apps/alias-server/test/aliasTests.js
Show All 31 Lines | before(async () => { | ||||
testMongoClient = new MongoClient(mongoUri); | testMongoClient = new MongoClient(mongoUri); | ||||
}); | }); | ||||
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 () { | // TODO have some registrations that underpaid and overpaid the fee | ||||
const registrationOutputScript = cashaddr.getOutputScriptFromAddress( | // TODO parseAliasTx on every length, p2pkh and p2sh addresses | ||||
config.aliasConstants.registrationAddress, | |||||
); | |||||
assert.deepEqual( | |||||
parseAliasTx( | |||||
testAddressAliases.txHistory[ | |||||
testAddressAliases.txHistory.findIndex( | |||||
i => | |||||
i.txid === | |||||
'9d9fd465f56a7946c48b2e214386b51d7968a3a40d46cc697036e4fc1cc644df', | |||||
) | |||||
], | |||||
config.aliasConstants, | |||||
registrationOutputScript, | |||||
), | |||||
testAddressAliases.allAliasTxs[ | |||||
testAddressAliases.allAliasTxs.findIndex( | |||||
i => | |||||
i.txid === | |||||
'9d9fd465f56a7946c48b2e214386b51d7968a3a40d46cc697036e4fc1cc644df', | |||||
) | |||||
], | |||||
); | |||||
}); | |||||
it('Correctly parses a 6-character alias transaction', function () { | |||||
const registrationOutputScript = cashaddr.getOutputScriptFromAddress( | |||||
config.aliasConstants.registrationAddress, | |||||
); | |||||
assert.deepEqual( | |||||
parseAliasTx( | |||||
testAddressAliases.txHistory[ | |||||
testAddressAliases.txHistory.findIndex( | |||||
i => | |||||
i.txid === | |||||
'36fdab59d25625b6ff3661aa5ab22a4893698fa5618e5e958e1d75bf921e6107', | |||||
) | |||||
], | |||||
config.aliasConstants, | |||||
registrationOutputScript, | |||||
), | |||||
testAddressAliases.allAliasTxs[ | |||||
testAddressAliases.allAliasTxs.findIndex( | |||||
i => | |||||
i.txid === | |||||
'36fdab59d25625b6ff3661aa5ab22a4893698fa5618e5e958e1d75bf921e6107', | |||||
) | |||||
], | |||||
); | |||||
}); | |||||
it('Returns false for an eToken transaction', function () { | it('Returns false for an eToken transaction', function () { | ||||
const registrationOutputScript = cashaddr.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( | ||||
▲ Show 20 Lines • Show All 148 Lines • ▼ Show 20 Lines | it('Correctly returns valid alias registrations at test address ecash:qp3c268rd5946l2f5m5es4x25f7ewu4sjvpy52pqa8 given some unconfirmed txs in history', async function () { | ||||
// This tests startup condition, so add no aliases to the database | // This tests startup condition, so add no aliases to the database | ||||
assert.deepEqual( | assert.deepEqual( | ||||
await registerAliases(testDb, confirmedUnsortedAliasTxs), | await registerAliases(testDb, confirmedUnsortedAliasTxs), | ||||
testAddressAliasesWithUnconfirmedTxs.validAliasTxs, | testAddressAliasesWithUnconfirmedTxs.validAliasTxs, | ||||
); | ); | ||||
// Wipe the database after this unit test | // Wipe the database after this unit test | ||||
await testDb.dropDatabase(); | await testDb.dropDatabase(); | ||||
}); | }); | ||||
it('Correctly parses a 3-character alias transaction for correct registration tx format and registration fee', function () { | |||||
const registrationOutputScript = cashaddr.getOutputScriptFromAddress( | |||||
config.aliasConstants.registrationAddress, | |||||
); | |||||
const thisTx = { | |||||
txid: 'cf6e83f79e62a067e490472acac8290e8ca7698c786d7b1fcaadcc1a8e66aebf', | |||||
version: 2, | |||||
inputs: [ | |||||
{ | |||||
prevOut: { | |||||
txid: '37b13f4b51c6a3d67fd93f92bbb009a9fbfa20dfb6ae62333e564affa29db3a6', | |||||
outIdx: 2, | |||||
}, | |||||
inputScript: | |||||
'473044022035c5d8f7c3e6afba45e8b6b0e9fd306c3e54ab4c73662149011a7c56259ecaf202200cc08308335fa8cbc2a584b4c2fe12eff7daf7d210763a3bf923d1a5ecd0fbed412102c237f49dd4c812f27b09d69d4c8a4da12744fda8ad63ce151fed2a3f41fd8795', | |||||
outputScript: | |||||
'76a91476458db0ed96fe9863fc1ccec9fa2cfab884b0f688ac', | |||||
value: '24988', | |||||
sequenceNo: 4294967295, | |||||
}, | |||||
], | |||||
outputs: [ | |||||
{ | |||||
value: '0', | |||||
outputScript: | |||||
'6a042e78656300036966701508d37c4c809fe9840e7bfa77b86bd47163f6fb6c60', | |||||
}, | |||||
{ | |||||
value: '556', | |||||
outputScript: | |||||
'a914d37c4c809fe9840e7bfa77b86bd47163f6fb6c6087', | |||||
}, | |||||
{ | |||||
value: '23977', | |||||
outputScript: | |||||
'76a91476458db0ed96fe9863fc1ccec9fa2cfab884b0f688ac', | |||||
}, | |||||
], | |||||
lockTime: 0, | |||||
block: { | |||||
height: 792422, | |||||
hash: '00000000000000001021d99a747d141c636bac5a0438ef8af7927b9f0f531b8e', | |||||
timestamp: '1684345054', | |||||
}, | |||||
timeFirstSeen: '1684344696', | |||||
size: 265, | |||||
isCoinbase: false, | |||||
network: 'XEC', | |||||
}; | |||||
const expectedResult = { | |||||
address: 'ecash:prfhcnyqnl5cgrnmlfmms675w93ld7mvvqd0y8lz07', | |||||
alias: 'ifp', | |||||
txid: 'cf6e83f79e62a067e490472acac8290e8ca7698c786d7b1fcaadcc1a8e66aebf', | |||||
blockheight: '792422', | |||||
}; | |||||
assert.deepEqual( | |||||
parseAliasTx( | |||||
thisTx, | |||||
config.aliasConstants, | |||||
registrationOutputScript, | |||||
), | |||||
expectedResult, | |||||
); | |||||
}); | |||||
}); | }); |