Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/tests #86

Draft
wants to merge 28 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
04edc30
chore(logic/Block): add test for `Block.create`
yoxira Oct 8, 2024
b947982
chore: add more tests for logic/block
yoxira Oct 13, 2024
47e627f
chore: add tests for logic/account
yoxira Oct 13, 2024
efa4341
chore: fix check format in `account.verifyPublicKey`
yoxira Oct 14, 2024
34cad58
chore: add tests for `logic.account.getAll()` and `logic.account.toDB()`
yoxira Oct 17, 2024
8291fdb
chore: add tests for `logic.account.set` and `logic.account.remove`
yoxira Oct 17, 2024
426f6cf
chore: add tests for logic/chat
yoxira Nov 6, 2024
496fc42
chore: add tests for logic/delegate
yoxira Nov 6, 2024
0775785
chore: add tests for logic/state
yoxira Nov 7, 2024
beedf9b
chore: write more tests and fix public key validation
yoxira Nov 25, 2024
47fd80d
chore: rename `savePromise` to `saveQuery` everywhere
yoxira Nov 25, 2024
467fecb
chore: fix jsdoc for a utility method
yoxira Nov 25, 2024
7177f44
chore: remove .prettierrc
yoxira Nov 25, 2024
b58d8b6
chore: clean up
yoxira Nov 25, 2024
488e660
chore: format the new tests
yoxira Nov 25, 2024
d493f17
chore: use .js extension in the new tests imports
yoxira Nov 25, 2024
234bfe8
test: fix test for `logic.chat.apply()` and `.undo()`
yoxira Nov 27, 2024
a635577
test: fix `modules.transactions.shared.getTransactions()` to get tran…
yoxira Nov 27, 2024
818dae3
test(`modules.accounts.shared.open()`): add edge case for invalid mme…
yoxira Nov 27, 2024
3a63258
chore: fix typo in a test's description
yoxira Nov 27, 2024
e6001a4
style: added a ✨semicolon✨
yoxira Nov 27, 2024
5b6d18d
chore: remove `test/node.js` import from unit tests where possible
yoxira Nov 28, 2024
44114b7
chore: refactor tests
yoxira Dec 1, 2024
5e9d018
fix(`logic.account.merge()`): multiple callback calls
yoxira Dec 1, 2024
afd7cbe
fix: throwing error instead of calling a callback
yoxira Dec 1, 2024
a3262e5
docs: add documentation for tests
yoxira Dec 1, 2024
c6a08d4
Merge branch 'dev' into chore/tests
yoxira Dec 1, 2024
d61f249
chore: downgrade chai
yoxira Dec 1, 2024
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
4 changes: 1 addition & 3 deletions logic/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,7 @@ Account.prototype.verifyPublicKey = function (publicKey) {
throw 'Invalid public key, must be 64 characters long';
}
// Check format
try {
Buffer.from(publicKey, 'hex');
} catch (e) {
if (!/^[0-9A-Fa-f]+$/.test(publicKey)) {
throw 'Invalid public key, must be a hex string';
}
}
Expand Down
9 changes: 9 additions & 0 deletions test/common/initModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ var modulesLoader = new function () {
case 'Peers':
new Logic(scope.logger, cb);
break;
case 'State':
async.series({
account: function (cb) {
new Account(scope.db, scope.schema, scope.logger, cb);
}
}, function (err, result) {
new Logic(scope.db, scope.ed, scope.schema, result.account, scope.logger, cb);
});
break;
default:
console.log('no Logic case initLogic');
}
Expand Down
13 changes: 13 additions & 0 deletions test/common/stubs/account.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const validAccount = {
address: "U777355171330060015",
unconfirmedBalance: "4509718944753",
balance: "4509718944753",
publicKey: "a9407418dafb3c8aeee28f3263fd55bae0f528a5697a9df0e77e6568b19dfe34",
unconfirmedSignature: 0,
secondSignature: 0,
secondPublicKey: null,
};

module.exports = {
validAccount,
};
163 changes: 163 additions & 0 deletions test/common/stubs/blocks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
const validBlock = {
id: "2970021393187988089",
version: 0,
timestamp: 224138470,
height: 74916,
previousBlock: "1859555445278782254",
numberOfTransactions: 4,
totalAmount: 10000000000,
totalFee: 100200000,
reward: 0,
payloadLength: 569,
payloadHash:
"2fcb011cb7540594ada9bb88e40c602257c21477c701f1b729573f5171165a74",
generatorPublicKey:
"f4011a1360ac2769e066c789acaaeffa9d707690d4d3f6085a7d52756fbc30d0",
generatorId: "U7821895274052553465",
blockSignature:
"2efc3964ff1bfe5913ccdac97aefa88514091557011760d29de28abb36a8345533dfbe28f407fd8d2a5f75af87d2bd342f913ef527bacb9537c0a4714fe0b30b",
confirmations: 13,
totalForged: "100200000",
};

const firstTransfer = {
id: "11011291491598217343",
height: 74916,
blockId: "1343081691583438166",
type: 0,
block_timestamp: 224138470,
timestamp: 224138454,
senderPublicKey:
"b0b4d346382aa07b23c0b733d040424532201b9eb22004b66a79d4b44e9d1449",
senderId: "U9781760580710719871",
recipientId: "U3189897341701072645",
recipientPublicKey:
"5da4a51dc0cdf2908b2bd63ef788604205f87531697cd978407fd15a6c358bff",
amount: 100000000,
fee: 50000000,
signature:
"1e21c8a786b802794e137fd964a72b17618a720e85e7df98244bfee854950ece5e3c9fe8bdf23b2ef27cbf1ed3ecaa7e7829a6cfd8b3a4d51e45ecdc5c716905",
signatures: [],
confirmations: 61,
asset: {},
};

const secondTransfer = {
id: "6518067615780126",
height: 74916,
blockId: "1343081691583438166",
type: 0,
block_timestamp: 224138470,
timestamp: 224138455,
senderPublicKey:
"b0b4d346382aa07b23c0b733d040424532201b9eb22004b66a79d4b44e9d1449",
senderId: "U9781760580710719871",
recipientId: "U3189897341701072645",
recipientPublicKey:
"5da4a51dc0cdf2908b2bd63ef788604205f87531697cd978407fd15a6c358bff",
amount: 9900000000,
fee: 50000000,
signature:
"d4d9ae872ae30a35ef5f0c0fc5cb0b9098dcc71b15b287d7e890c9d9c9d5493348dfaf3ad14f7ccae25214dc987e5a0f5440ebdfb0e2e93b6798b2aedc0f8a04",
signatures: [],
confirmations: 61,
asset: {},
};

const firstMessage = {
id: "449774133478944478",
height: 74916,
blockId: "1343081691583438166",
type: 8,
block_timestamp: 224138470,
timestamp: 224138456,
senderPublicKey:
"b0b4d346382aa07b23c0b733d040424532201b9eb22004b66a79d4b44e9d1449",
senderId: "U9781760580710719871",
recipientId: "U3189897341701072645",
recipientPublicKey:
"5da4a51dc0cdf2908b2bd63ef788604205f87531697cd978407fd15a6c358bff",
amount: 0,
fee: 100000,
signature:
"f9f17e8e8935464c50ffa2a619321c25f3a7913a01ff547c54d419ff45a11d2466ed0dc6109dcc482051e3be410cdb68a169d44c42dc16ed62a4ff81393fd30f",
signatures: [],
confirmations: 61,
asset: {
chat: {
message: "fd38e525f10ff6980cab97d7edb8a78f6b12b445480f",
own_message: "44738b0599ff450d0d3d4ac86aa6c0f859fb033a8a74fb4a",
type: 1,
},
},
};

const secondMessage = {
id: "8266147080308035705",
height: 74916,
blockId: "1343081691583438166",
type: 8,
block_timestamp: 224138470,
timestamp: 224138458,
senderPublicKey:
"b0b4d346382aa07b23c0b733d040424532201b9eb22004b66a79d4b44e9d1449",
senderId: "U9781760580710719871",
recipientId: "U3189897341701072645",
recipientPublicKey:
"5da4a51dc0cdf2908b2bd63ef788604205f87531697cd978407fd15a6c358bff",
amount: 0,
fee: 100000,
signature:
"13ab79bdc259f1fa2d1d0a73ccf7ca53abb603d2f56c96a1fe9dc46303acce10158ad88b79c5872a952d3bbf661e97393258356c1c0968427762203e27ac820e",
signatures: [],
confirmations: 61,
asset: {
chat: {
message: "b5e490e0e284cd779e8e86e638a0d9497fcd396abe934a",
own_message: "2f58bb7bcbe7cc5f6c1e1d9a7c7b81fdc5513f96cc8c1a0f",
type: 1,
},
},
};

const validBlockTransactions = [
firstTransfer,
secondTransfer,
firstMessage,
secondMessage,
];

const validPreviousBlock = {
id: "1859555445278782254",
version: 0,
timestamp: 224138465,
height: 74915,
previousBlock: "15739298621941223523",
numberOfTransactions: 0,
totalAmount: 0,
totalFee: 0,
reward: 0,
payloadLength: 0,
payloadHash:
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
generatorPublicKey:
"2e6331291833dee33649f2e0b1c864f9bd8d2618faa144d36e9b4bec65209f6a",
generatorId: "U123464595396329758",
blockSignature:
"f8c1e2b69c78fa3aa242879db25c40b19f70393f3a3408a78de4db986c157646df6ab5d9a4beeac8d184036254684b7cffbc22f470c3733324f9375b33787301",
confirmations: 169,
totalForged: "0",
};

const validPreviousBlockTransactions = [];

module.exports = {
validBlock,
validBlockTransactions,
validPreviousBlock,
validPreviousBlockTransactions,
firstTransfer,
secondTransfer,
firstMessage,
secondMessage
};
12 changes: 12 additions & 0 deletions test/common/stubs/delegate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const ed = require('../../../helpers/ed.js');

// 'market' delegate
const delegatePassphrase = 'rally clean ladder crane gadget century timber jealous shine scorpion beauty salon';
const delegateHash = ed.createPassPhraseHash(delegatePassphrase);
const delegateKeyPair = ed.makeKeypair(delegateHash);

module.exports = {
delegatePassphrase,
delegateHash,
delegateKeyPair
};
Loading