Skip to content

Commit

Permalink
Add Dynamic Address Book unit tests (#2459)
Browse files Browse the repository at this point in the history
* chore: getter naming convention

Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>

* fix: setters should work only when frozen

Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>

* fix: NodeUpdateTransaction was missing nodeid in tx body

Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>

* test(wip): DAB unit tests

Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>

* test: change byte test names

Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>

* test: use ED25519 instead of depricated methods

Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>

* test: dont use async functions and await when not necessary

Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>

* test: rename typo test name

Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>

* test: use naming convention camelCase

Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>

* test: add comment for variable clarity

Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>

* test: no need for TEST prefix

Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>

* update describe block names

Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>

* test: use const as error message

Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>

* test: remove wrong error message

Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>

* test: add gossip and service endpoints tests for from-to bytes test

Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>

* test: dont use join for endpoints

Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>

* test: use underscore because we dont use element

Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>

* test: use error message for frozen tests as constant

Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>

* test: try catch consistency

Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>

---------

Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>
  • Loading branch information
ivaylonikolov7 authored Aug 20, 2024
1 parent 507fdad commit 05d3c9c
Show file tree
Hide file tree
Showing 6 changed files with 600 additions and 16 deletions.
21 changes: 14 additions & 7 deletions src/node/NodeCreateTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ export default class NodeCreateTransaction extends Transaction {
* @returns {NodeCreateTransaction}
*/
setAccountId(accountId) {
this._requireNotFrozen();
this._accountId =
accountId instanceof AccountId
? accountId
Expand All @@ -207,7 +208,7 @@ export default class NodeCreateTransaction extends Transaction {
* @description Get node account identifier.
* @returns {?AccountId}
*/
get getAccountId() {
get accountId() {
return this._accountId;
}

Expand All @@ -217,6 +218,7 @@ export default class NodeCreateTransaction extends Transaction {
* @returns {NodeCreateTransaction}
*/
setDescription(description) {
this._requireNotFrozen();
if (description.length > DESCRIPTION_MAX_LENGTH) {
throw new Error(
`Description must be at most ${DESCRIPTION_MAX_LENGTH} characters.`,
Expand All @@ -231,7 +233,7 @@ export default class NodeCreateTransaction extends Transaction {
* @description Get description of the node.
* @returns {?string}
*/
get getDescription() {
get description() {
return this._description;
}

Expand All @@ -241,6 +243,7 @@ export default class NodeCreateTransaction extends Transaction {
* @returns {NodeCreateTransaction}
*/
setGossipEndpoints(gossipEndpoints) {
this._requireNotFrozen();
if (gossipEndpoints.length == 0) {
throw new Error("GossipEndpoints list must not be empty.");
}
Expand All @@ -260,7 +263,7 @@ export default class NodeCreateTransaction extends Transaction {
* @description Get list of service endpoints for gossip.
* @returns {?Array<ServiceEndpoint>}
*/
get getGossipEndpoints() {
get gossipEndpoints() {
return this._gossipEndpoints;
}

Expand All @@ -282,6 +285,7 @@ export default class NodeCreateTransaction extends Transaction {
* @returns {NodeCreateTransaction}
*/
setServiceEndpoints(serviceEndpoints) {
this._requireNotFrozen();
if (serviceEndpoints.length == 0) {
throw new Error("ServiceEndpoints list must not be empty.");
}
Expand All @@ -301,7 +305,7 @@ export default class NodeCreateTransaction extends Transaction {
* @description Get list of service endpoints for gRPC calls.
* @returns {?Array<ServiceEndpoint>}
*/
get getServiceEndpoints() {
get serviceEndpoints() {
return this._serviceEndpoints;
}

Expand All @@ -323,6 +327,7 @@ export default class NodeCreateTransaction extends Transaction {
* @returns {NodeCreateTransaction}
*/
setGossipCaCertificate(bytes) {
this._requireNotFrozen();
if (bytes.length == 0) {
throw new Error("GossipCaCertificate must not be empty.");
}
Expand All @@ -336,7 +341,7 @@ export default class NodeCreateTransaction extends Transaction {
* @description Get certificate used to sign gossip events.
* @returns {?Uint8Array}
*/
get getGossipCaCertificate() {
get gossipCaCertificate() {
return this._gossipCaCertificate;
}

Expand All @@ -346,6 +351,7 @@ export default class NodeCreateTransaction extends Transaction {
* @returns {NodeCreateTransaction}
*/
setCertificateHash(bytes) {
this._requireNotFrozen();
this._grpcCertificateHash = bytes;

return this;
Expand All @@ -355,7 +361,7 @@ export default class NodeCreateTransaction extends Transaction {
* @description Get hash of the node gRPC TLS certificate.
* @returns {?Uint8Array}
*/
get getCertificateHash() {
get certificateHash() {
return this._grpcCertificateHash;
}

Expand All @@ -365,6 +371,7 @@ export default class NodeCreateTransaction extends Transaction {
* @returns {NodeCreateTransaction}
*/
setAdminKey(adminKey) {
this._requireNotFrozen();
this._adminKey = adminKey;

return this;
Expand All @@ -374,7 +381,7 @@ export default class NodeCreateTransaction extends Transaction {
* @description Get administrative key controlled by the node operator.
* @returns {?Key}
*/
get getAdminKey() {
get adminKey() {
return this._adminKey;
}

Expand Down
2 changes: 1 addition & 1 deletion src/node/NodeDeleteTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export default class NodeDeleteTransaction extends Transaction {
* @description Get consensus node identifier.
* @returns {?Long}
*/
get getNodeId() {
get nodeId() {
return this._nodeId;
}

Expand Down
27 changes: 19 additions & 8 deletions src/node/NodeUpdateTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ export default class NodeUpdateTransaction extends Transaction {
* @returns {NodeUpdateTransaction}
*/
setNodeId(nodeId) {
this._requireNotFrozen();
this._nodeId = nodeId;

return this;
Expand All @@ -220,7 +221,7 @@ export default class NodeUpdateTransaction extends Transaction {
* @description Get consensus node identifier in the network state.
* @returns {?Long}
*/
get getNodeId() {
get nodeId() {
return this._nodeId;
}

Expand All @@ -230,6 +231,7 @@ export default class NodeUpdateTransaction extends Transaction {
* @returns {NodeUpdateTransaction}
*/
setAccountId(accountId) {
this._requireNotFrozen();
this._accountId =
accountId instanceof AccountId
? accountId
Expand All @@ -242,7 +244,7 @@ export default class NodeUpdateTransaction extends Transaction {
* @description Get desired new account identifier of the node.
* @returns {?AccountId}
*/
get getAccountId() {
get accountId() {
return this._accountId;
}

Expand All @@ -252,6 +254,7 @@ export default class NodeUpdateTransaction extends Transaction {
* @returns {NodeUpdateTransaction}
*/
setDescription(description) {
this._requireNotFrozen();
if (description.length > DESCRIPTION_MAX_LENGTH) {
throw new Error(
`Description must be at most ${DESCRIPTION_MAX_LENGTH} characters.`,
Expand All @@ -274,7 +277,7 @@ export default class NodeUpdateTransaction extends Transaction {
* @description Get description of the node.
* @returns {?string}
*/
get getDescription() {
get description() {
return this._description;
}

Expand All @@ -284,6 +287,7 @@ export default class NodeUpdateTransaction extends Transaction {
* @returns {NodeUpdateTransaction}
*/
setGossipEndpoints(gossipEndpoints) {
this._requireNotFrozen();
if (gossipEndpoints.length == 0) {
throw new Error("GossipEndpoints list must not be empty.");
}
Expand All @@ -303,7 +307,7 @@ export default class NodeUpdateTransaction extends Transaction {
* @description Get list of service endpoints for gossip.
* @returns {?Array<ServiceEndpoint>}
*/
get getGossipEndpoints() {
get gossipEndpoints() {
return this._gossipEndpoints;
}

Expand All @@ -313,6 +317,7 @@ export default class NodeUpdateTransaction extends Transaction {
* @returns {NodeUpdateTransaction}
*/
addGossipEndpoint(endpoint) {
this._requireNotFrozen();
if (this._gossipEndpoints != null) {
this._gossipEndpoints.push(endpoint);
}
Expand All @@ -325,6 +330,7 @@ export default class NodeUpdateTransaction extends Transaction {
* @returns {NodeUpdateTransaction}
*/
setServiceEndpoints(serviceEndpoints) {
this._requireNotFrozen();
if (serviceEndpoints.length == 0) {
throw new Error("ServiceEndpoints list must not be empty.");
}
Expand All @@ -344,7 +350,7 @@ export default class NodeUpdateTransaction extends Transaction {
* @description Get list of service endpoints for gRPC calls.
* @returns {?Array<ServiceEndpoint>}
*/
get getServiceEndpoints() {
get serviceEndpoints() {
return this._serviceEndpoints;
}

Expand All @@ -354,6 +360,7 @@ export default class NodeUpdateTransaction extends Transaction {
* @returns {NodeUpdateTransaction}
*/
addServiceEndpoint(endpoint) {
this._requireNotFrozen();
if (this._serviceEndpoints != null) {
this._serviceEndpoints.push(endpoint);
}
Expand All @@ -366,6 +373,7 @@ export default class NodeUpdateTransaction extends Transaction {
* @returns {NodeUpdateTransaction}
*/
setGossipCaCertificate(bytes) {
this._requireNotFrozen();
if (bytes.length == 0) {
throw new Error("GossipCaCertificate must not be empty.");
}
Expand All @@ -379,7 +387,7 @@ export default class NodeUpdateTransaction extends Transaction {
* @description Get certificate used to sign gossip events.
* @returns {?Uint8Array}
*/
get getGossipCaCertificate() {
get gossipCaCertificate() {
return this._gossipCaCertificate;
}

Expand All @@ -389,6 +397,7 @@ export default class NodeUpdateTransaction extends Transaction {
* @returns {NodeUpdateTransaction}
*/
setCertificateHash(bytes) {
this._requireNotFrozen();
this._grpcCertificateHash = bytes;

return this;
Expand All @@ -398,7 +407,7 @@ export default class NodeUpdateTransaction extends Transaction {
* @description Get hash of the node gRPC TLS certificate.
* @returns {?Uint8Array}
*/
get getCertificateHash() {
get certificateHash() {
return this._grpcCertificateHash;
}

Expand All @@ -408,6 +417,7 @@ export default class NodeUpdateTransaction extends Transaction {
* @returns {NodeUpdateTransaction}
*/
setAdminKey(adminKey) {
this._requireNotFrozen();
this._adminKey = adminKey;

return this;
Expand All @@ -417,7 +427,7 @@ export default class NodeUpdateTransaction extends Transaction {
* @description Get administrative key controlled by the node operator.
* @returns {?Key}
*/
get getAdminKey() {
get adminKey() {
return this._adminKey;
}

Expand Down Expand Up @@ -481,6 +491,7 @@ export default class NodeUpdateTransaction extends Transaction {
},
adminKey:
this._adminKey != null ? this._adminKey._toProtobufKey() : null,
nodeId: this._nodeId != null ? this._nodeId : null,
};
}

Expand Down
Loading

0 comments on commit 05d3c9c

Please sign in to comment.