File tree 3 files changed +15
-4
lines changed
3 files changed +15
-4
lines changed Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
+
3
4
const _ = require ( 'lodash' ) ;
5
+ const assert = require ( 'assert' ) ;
4
6
const util = require ( 'util' ) ;
5
7
const url = require ( 'url' ) ;
6
8
const HttpsProxyAgent = require ( 'https-proxy-agent' ) ;
@@ -905,6 +907,9 @@ Server.prototype._feeTxUnit = function() {
905
907
*/
906
908
907
909
Server . prototype . _reserve = function ( ownerCount ) {
910
+ // We should be in a valid state before calling this method
911
+ assert ( this . _reserve_base && this . _reserve_inc ) ;
912
+
908
913
const reserve_base = Amount . from_json ( String ( this . _reserve_base ) ) ;
909
914
const reserve_inc = Amount . from_json ( String ( this . _reserve_inc ) ) ;
910
915
const owner_count = ownerCount || 0 ;
@@ -913,7 +918,7 @@ Server.prototype._reserve = function(ownerCount) {
913
918
throw new Error ( 'Owner count must not be negative.' ) ;
914
919
}
915
920
916
- return reserve_base . add ( reserve_inc . product_human ( owner_count ) ) ;
921
+ return reserve_base . add ( reserve_inc . multiply ( owner_count ) ) ;
917
922
} ;
918
923
919
924
/**
Original file line number Diff line number Diff line change @@ -935,11 +935,10 @@ describe('Remote', function() {
935
935
remote . feeTxUnit ( 10 ) . to_json ( ) ;
936
936
} ) ;
937
937
} ) ;
938
- it ( 'Get reserve' , function ( ) {
938
+ it ( 'reserve() before reserve rate known ' , function ( ) {
939
939
remote . _connected = true ;
940
940
remote . _servers [ 0 ] . _connected = true ;
941
- assert . strictEqual ( remote . reserve ( 1 ) . to_json ( ) , 'NaN' ) ;
942
- remote . _servers = [ ] ;
941
+ // Throws because the server has not had reserve_inc, reserve_base set
943
942
assert . throws ( function ( ) {
944
943
remote . reserve ( 10 ) . to_json ( ) ;
945
944
} ) ;
Original file line number Diff line number Diff line change @@ -1063,6 +1063,13 @@ describe('Server', function() {
1063
1063
assert . strictEqual ( server . _reserve ( ) . to_json ( ) , '20000000' ) ;
1064
1064
} ) ;
1065
1065
1066
+ it ( 'Compute reserve, positive OwnerCount' , function ( ) {
1067
+ const server = new Server ( new Remote ( ) , 'ws://localhost:5748' ) ;
1068
+ server . _reserve_base = 20000000 ;
1069
+ server . _reserve_inc = 5000000 ;
1070
+ assert . strictEqual ( server . _reserve ( 4 ) . to_json ( ) , '40000000' ) ;
1071
+ } ) ;
1072
+
1066
1073
it ( 'Cache hostid' , function ( done ) {
1067
1074
const wss = new ws . Server ( {
1068
1075
port : 5748
You can’t perform that action at this time.
0 commit comments