Best JavaScript code snippet using devicefarmer-stf
ValidateLedger.gs
Source:ValidateLedger.gs
...36 ledgerRecords = [37 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),38 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'ABC', '', 200, '', 'IB', 'USD', '', 600, '', '', '')39 ];40 validationError = new ValidationError(`Trade row 4: Debit asset (ABC) is not found in the Assets sheet.`, 4, 'debitAsset');41 testValidateLedger('Debit asset not found', assetRecords, ledgerRecords, validationError);42 assetRecords = [43 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', '')44 ];45 ledgerRecords = [46 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, '', '', '')47 ];48 validationError = new ValidationError(`Trade row 3: Credit asset (LMN) is not found in the Assets sheet.`, 3, 'creditAsset');49 testValidateLedger('Credit asset not found', assetRecords, ledgerRecords, validationError);50 assetRecords = [51 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),52 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')53 ];54 ledgerRecords = [55 new LedgerRecord('#', 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, '', '', '')56 ];57 validationError = new ValidationError(`Trade row 3: Invalid date.`, 3, 'date');58 testValidateLedger('Invalid date', assetRecords, ledgerRecords, validationError);59 assetRecords = [60 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),61 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')62 ];63 ledgerRecords = [64 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, '', '', ''),65 new LedgerRecord(new Date(2020, 3, 3), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, '', '', ''),66 new LedgerRecord(new Date(2020, 3, 2), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, '', '', '')67 ];68 validationError = new ValidationError(`Trade row 5: Dates must be in chronological or reverse chronological order.`, 5, 'date');69 testValidateLedger('Dates not chronological or reverse chronological order', assetRecords, ledgerRecords, validationError);70 assetRecords = [71 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),72 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')73 ];74 ledgerRecords = [75 new LedgerRecord(new Date(3020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, '', '', '')76 ];77 validationError = new ValidationError(`Trade row 3: Date must be in the past.`, 3, 'date');78 testValidateLedger('Date in future', assetRecords, ledgerRecords, validationError);79 assetRecords = [80 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),81 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')82 ];83 ledgerRecords = [84 new LedgerRecord(new Date(2020, 3, 1), '', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, '', '', '')85 ];86 validationError = new ValidationError(`Ledger row 3: No action specified.`, 3, 'action');87 testValidateLedger('No action', assetRecords, ledgerRecords, validationError);88 assetRecords = [89 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),90 new AssetRecord('EUR', 'Fiat', 2, '', '', '', ''),91 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')92 ];93 ledgerRecords = [94 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'EUR', '#', 2000, '', 'IB', 'LMN', '', 1000, '', '', '')95 ];96 validationError = new ValidationError(`Trade row 3: Debit exchange rate is not valid (number or blank).`, 3, 'debitExRate');97 testValidateLedger('Invalid debit exrate', assetRecords, ledgerRecords, validationError);98 assetRecords = [99 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),100 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')101 ];102 ledgerRecords = [103 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', '#', '', 'IB', 'LMN', '', 1000, '', '', '')104 ];105 validationError = new ValidationError(`Trade row 3: Debit amount is not valid (number or blank).`, 3, 'debitAmount');106 testValidateLedger('Invalid debit amount', assetRecords, ledgerRecords, validationError);107 assetRecords = [108 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),109 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')110 ];111 ledgerRecords = [112 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '#', 'IB', 'LMN', '', 1000, '', '', '')113 ];114 validationError = new ValidationError(`Trade row 3: Debit fee is not valid (number or blank).`, 3, 'debitFee');115 testValidateLedger('Invalid debit fee', assetRecords, ledgerRecords, validationError);116 assetRecords = [117 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),118 new AssetRecord('EUR', 'Fiat', 2, '', '', '', ''),119 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')120 ];121 ledgerRecords = [122 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'EUR', '', 2000, '', 'IB', 'LMN', '#', 1000, '', '', '')123 ];124 validationError = new ValidationError(`Trade row 3: Credit exchange rate is not valid (number or blank).`, 3, 'creditExRate');125 testValidateLedger('Invalid credit exrate', assetRecords, ledgerRecords, validationError);126 assetRecords = [127 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),128 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')129 ];130 ledgerRecords = [131 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', '#', '', '', '')132 ];133 validationError = new ValidationError(`Trade row 3: Credit amount is not valid (number or blank).`, 3, 'creditAmount');134 testValidateLedger('Invalid credit amount', assetRecords, ledgerRecords, validationError);135 assetRecords = [136 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),137 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')138 ];139 ledgerRecords = [140 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, '#', '', '')141 ];142 validationError = new ValidationError(`Trade row 3: Credit fee is not valid (number or blank).`, 3, 'creditFee');143 testValidateLedger('Invalid credit fee', assetRecords, ledgerRecords, validationError);144 assetRecords = [145 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),146 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')147 ];148 ledgerRecords = [149 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, '', '', '#')150 ];151 validationError = new ValidationError(`Trade row 3: Lot matching (#) is not valid (FIFO, LIFO, HIFO, LOFO) or blank.`, 3, 'lotMatching');152 testValidateLedger('Invalid lot matching', assetRecords, ledgerRecords, validationError);153 assetRecords = [154 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', '')155 ];156 ledgerRecords = [157 new LedgerRecord(new Date(2020, 3, 1), 'Sleep', '', '', '', '', '', '', '', '', '', '', '')158 ];159 validationError = new ValidationError(`Ledger row 3: Action (Sleep) is invalid.`, 3, 'action');160 testValidateLedger('Invalid Action', assetRecords, ledgerRecords, validationError);161 assetRecords = [162 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),163 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')164 ];165 ledgerRecords = [166 new LedgerRecord(new Date(2020, 3, 3), 'Trade', 'USD', '', -2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),167 new LedgerRecord(new Date(2020, 3, 2), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),168 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', '')169 ];170 validationError = new ValidationError(`Trade row 3: Debit amount must be greater than or equal to 0.`, 3, 'debitAmount');171 testValidateLedger('Reverse chronological order with error', assetRecords, ledgerRecords, validationError);172 assetRecords = [173 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),174 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')175 ];176 ledgerRecords = [177 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),178 new LedgerRecord(new Date(2020, 3, 1), 'Skip', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),179 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', -2000, '', 'IB', 'LMN', '', 1000, 0, '', '')180 ];181 validationError = new ValidationError(`Trade row 5: Debit amount must be greater than or equal to 0.`, 5, 'debitAmount');182 testValidateLedger('Skip then error', assetRecords, ledgerRecords, validationError);183 assetRecords = [184 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),185 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')186 ];187 ledgerRecords = [188 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),189 new LedgerRecord(new Date(2020, 3, 1), 'Skip', 'USD', '', -2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),190 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', '')191 ];192 validationError = null;193 testValidateLedger('Skip error valid', assetRecords, ledgerRecords, validationError);194 assetRecords = [195 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),196 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')197 ];198 ledgerRecords = [199 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),200 new LedgerRecord(new Date(2020, 3, 1), 'Stop', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),201 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', -2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),202 ];203 validationError = null;204 testValidateLedger('Stop then error valid', assetRecords, ledgerRecords, validationError);205}206function validateLedgerTransfer() {207 QUnit.module('Validate Ledger Transfer');208 let assetRecords;209 let ledgerRecords;210 let validationError;211 assetRecords = [212 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),213 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')214 ];215 ledgerRecords = [216 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', 'EUR', '', 2000, 10, 'IB', '', '', '', '', '', '')217 ];218 validationError = null;219 testValidateLedger('Transfer fiat to bank with fee valid', assetRecords, ledgerRecords, validationError);220 assetRecords = [221 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),222 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')223 ];224 ledgerRecords = [225 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', 'EUR', '', 2000, '', 'IB', '', '', '', '', '', '')226 ];227 validationError = null;228 testValidateLedger('Transfer fiat to bank no fee valid', assetRecords, ledgerRecords, validationError);229 assetRecords = [230 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),231 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')232 ];233 ledgerRecords = [234 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', '', '', '', '', '', 'EUR', '', 2000, '', 'IB', '')235 ];236 validationError = null;237 testValidateLedger('Transfer fiat from bank valid', assetRecords, ledgerRecords, validationError);238 assetRecords = [239 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),240 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')241 ];242 ledgerRecords = [243 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', 'EUR', '', 2000, 10, 'IB', '', '', '', '', 'Kraken', '')244 ];245 validationError = null;246 testValidateLedger('Transfer fiat with fee valid', assetRecords, ledgerRecords, validationError);247 assetRecords = [248 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),249 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')250 ];251 ledgerRecords = [252 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', 'EUR', '', 2000, '', 'IB', '', '', '', '', 'Kraken', '')253 ];254 validationError = null;255 testValidateLedger('Transfer fiat no fee valid', assetRecords, ledgerRecords, validationError);256 assetRecords = [257 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),258 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')259 ];260 ledgerRecords = [261 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'Kraken', 'ADA', '', 2010, '', '', ''),262 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', 'ADA', '', 2000, 10, 'Kraken', '', '', '', '', 'Ledger', '')263 ];264 validationError = null;265 testValidateLedger('Transfer asset with fee valid', assetRecords, ledgerRecords, validationError);266 assetRecords = [267 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),268 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')269 ];270 ledgerRecords = [271 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'Kraken', 'ADA', '', 2000, '', '', ''),272 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', 'ADA', '', 2000, '', 'Kraken', '', '', '', '', 'Ledger', '')273 ];274 validationError = null;275 testValidateLedger('Transfer asset no fee valid', assetRecords, ledgerRecords, validationError);276 assetRecords = [277 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', '')278 ];279 ledgerRecords = [280 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', '', '', 2000, '', 'IB', '', '', '', '', '', '')281 ];282 validationError = new ValidationError(`Transfer row 3: No debit or credit asset specified.`, 3, 'debitAsset');283 testValidateLedger('Transfer no debit or credit asset', assetRecords, ledgerRecords, validationError);284 assetRecords = [285 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),286 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')287 ];288 ledgerRecords = [289 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', 'EUR', '', 2000, '', 'IB', 'USD', '', '', '', '', '')290 ];291 validationError = new ValidationError(`Transfer row 3: Either debit or credit asset must be specified, but not both.`, 3, 'debitAsset');292 testValidateLedger('Transfer both debit and credit asset', assetRecords, ledgerRecords, validationError);293 assetRecords = [294 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),295 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')296 ];297 ledgerRecords = [298 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'Kraken', 'ADA', '', 2000, '', '', ''),299 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', '', '', '', '', '', 'ADA', '', 2000, '', 'Ledger', '')300 ];301 validationError = new ValidationError(`Transfer row 4: Credit asset must be fiat (or blank).`, 4, 'creditAsset');302 testValidateLedger('Transfer asset credit asset', assetRecords, ledgerRecords, validationError);303 assetRecords = [304 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),305 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')306 ];307 ledgerRecords = [308 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', 'EUR', 1.2, 2000, '', 'IB', '', '', '', '', '', '')309 ];310 validationError = new ValidationError(`Transfer row 3: Leave debit exchange rate blank.`, 3, 'debitExRate');311 testValidateLedger('Transfer debit exrate', assetRecords, ledgerRecords, validationError);312 assetRecords = [313 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),314 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')315 ];316 ledgerRecords = [317 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', 'EUR', '', 2000, '', 'IB', '', 1.2, '', '', '', '')318 ];319 validationError = new ValidationError(`Transfer row 3: Leave credit exchange rate blank.`, 3, 'creditExRate');320 testValidateLedger('Transfer credit exrate', assetRecords, ledgerRecords, validationError);321 assetRecords = [322 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),323 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')324 ];325 ledgerRecords = [326 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', 'EUR', '', 2000, '', 'IB', '', '', '', 10, '', '')327 ];328 validationError = new ValidationError(`Transfer row 3: Leave credit fee blank.`, 3, 'creditFee');329 testValidateLedger('Transfer credit fee', assetRecords, ledgerRecords, validationError);330 assetRecords = [331 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),332 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')333 ];334 ledgerRecords = [335 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', '', '', 2000, '', '', 'EUR', '', 2000, '', 'IB', '')336 ];337 validationError = new ValidationError(`Transfer row 3: Leave debit amount blank when credit asset is specified.`, 3, 'debitAmount');338 testValidateLedger('Transfer fiat from bank debit amount', assetRecords, ledgerRecords, validationError);339 assetRecords = [340 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),341 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')342 ];343 ledgerRecords = [344 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', '', '', '', 10, '', 'EUR', '', 2000, '', 'IB', '')345 ];346 validationError = new ValidationError(`Transfer row 3: Leave debit fee blank when credit asset is specified.`, 3, 'debitFee');347 testValidateLedger('Transfer fiat from bank debit fee', assetRecords, ledgerRecords, validationError);348 assetRecords = [349 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),350 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')351 ];352 ledgerRecords = [353 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', '', '', '', '', 'Kraken', 'EUR', '', 2000, '', 'IB', '')354 ];355 validationError = new ValidationError(`Transfer row 3: Leave debit wallet blank when credit asset is specified.`, 3, 'debitWalletName');356 testValidateLedger('Transfer fiat from bank debit wallet', assetRecords, ledgerRecords, validationError);357 assetRecords = [358 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),359 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')360 ];361 ledgerRecords = [362 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', '', '', '', '', '', 'EUR', '', '', '', 'IB', '')363 ];364 validationError = new ValidationError(`Transfer row 3: Credit amount must be specified when credit asset is specified.`, 3, 'creditAmount');365 testValidateLedger('Transfer fiat from bank no credit amount', assetRecords, ledgerRecords, validationError);366 assetRecords = [367 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),368 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')369 ];370 ledgerRecords = [371 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', '', '', '', '', '', 'EUR', '', -2000, '', 'IB', '')372 ];373 validationError = new ValidationError(`Transfer row 3: Credit amount must be greater than 0 when credit asset is specified.`, 3, 'creditAmount');374 testValidateLedger('Transfer fiat from bank negative credit amount', assetRecords, ledgerRecords, validationError);375 assetRecords = [376 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),377 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')378 ];379 ledgerRecords = [380 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', '', '', '', '', '', 'EUR', '', 0, '', 'IB', '')381 ];382 validationError = new ValidationError(`Transfer row 3: Credit amount must be greater than 0 when credit asset is specified.`, 3, 'creditAmount');383 testValidateLedger('Transfer fiat from bank zero credit amount', assetRecords, ledgerRecords, validationError);384 assetRecords = [385 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),386 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')387 ];388 ledgerRecords = [389 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', '', '', '', '', '', 'EUR', '', 2000, '', '', '')390 ];391 validationError = new ValidationError(`Transfer row 3: Credit wallet must be specified when credit asset is specified.`, 3, 'creditWalletName');392 testValidateLedger('Transfer fiat from bank no credit wallet', assetRecords, ledgerRecords, validationError);393 assetRecords = [394 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),395 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')396 ];397 ledgerRecords = [398 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', 'EUR', '', '', '', 'IB', '', '', '', '', '', '')399 ];400 validationError = new ValidationError(`Transfer row 3: Debit amount must be specified when debit asset is specified.`, 3, 'debitAmount');401 testValidateLedger('Transfer fiat to bank no debit amount', assetRecords, ledgerRecords, validationError);402 assetRecords = [403 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),404 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')405 ];406 ledgerRecords = [407 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', 'EUR', '', -2000, '', 'IB', '', '', '', '', '', '')408 ];409 validationError = new ValidationError(`Transfer row 3: Debit amount must be greater than 0 when debit asset is specified.`, 3, 'debitAmount');410 testValidateLedger('Transfer fiat to bank negative debit amount', assetRecords, ledgerRecords, validationError);411 assetRecords = [412 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),413 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')414 ];415 ledgerRecords = [416 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', 'EUR', '', 0, '', 'IB', '', '', '', '', '', '')417 ];418 validationError = new ValidationError(`Transfer row 3: Debit amount must be greater than 0 when debit asset is specified.`, 3, 'debitAmount');419 testValidateLedger('Transfer fiat to bank zero debit amount', assetRecords, ledgerRecords, validationError);420 assetRecords = [421 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),422 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')423 ];424 ledgerRecords = [425 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', 'EUR', '', 2000, -10, 'IB', '', '', '', '', '', '')426 ];427 validationError = new ValidationError(`Transfer row 3: Debit fee must be greater than or equal to 0 (or blank) when debit asset is specified.`, 3, 'debitFee');428 testValidateLedger('Transfer fiat to bank negative debit fee', assetRecords, ledgerRecords, validationError);429 assetRecords = [430 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),431 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')432 ];433 ledgerRecords = [434 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', 'EUR', '', 2000, 0, 'IB', '', '', '', '', '', '')435 ];436 validationError = null;437 testValidateLedger('Transfer fiat to bank zero debit fee valid', assetRecords, ledgerRecords, validationError);438 assetRecords = [439 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),440 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')441 ];442 ledgerRecords = [443 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', 'EUR', '', 2000, '', '', '', '', '', '', '', '')444 ];445 validationError = new ValidationError(`Transfer row 3: Debit wallet must be specified when debit asset is specified.`, 3, 'debitWalletName');446 testValidateLedger('Transfer fiat to bank no debit wallet', assetRecords, ledgerRecords, validationError);447 assetRecords = [448 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),449 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')450 ];451 ledgerRecords = [452 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', 'EUR', '', 2000, '', 'IB', '', '', 2000, '', '', '')453 ];454 validationError = new ValidationError(`Transfer row 3: Leave credit amount blank when credit asset is not specified.`, 3, 'creditAmount');455 testValidateLedger('Transfer fiat to bank credit amount', assetRecords, ledgerRecords, validationError);456 assetRecords = [457 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),458 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')459 ];460 ledgerRecords = [461 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', 'EUR', '', '', '', 'IB', '', '', '', '', 'Kraken', '')462 ];463 validationError = new ValidationError(`Transfer row 3: Debit amount must be specified when debit asset is specified.`, 3, 'debitAmount');464 testValidateLedger('Transfer fiat no debit amount', assetRecords, ledgerRecords, validationError);465 assetRecords = [466 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),467 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')468 ];469 ledgerRecords = [470 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', 'EUR', '', -2000, '', 'IB', '', '', '', '', 'Kraken', '')471 ];472 validationError = new ValidationError(`Transfer row 3: Debit amount must be greater than 0 when debit asset is specified.`, 3, 'debitAmount');473 testValidateLedger('Transfer fiat negative debit amount', assetRecords, ledgerRecords, validationError);474 assetRecords = [475 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),476 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')477 ];478 ledgerRecords = [479 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', 'EUR', '', 0, '', 'IB', '', '', '', '', 'Kraken', '')480 ];481 validationError = new ValidationError(`Transfer row 3: Debit amount must be greater than 0 when debit asset is specified.`, 3, 'debitAmount');482 testValidateLedger('Transfer fiat zero debit amount', assetRecords, ledgerRecords, validationError);483 assetRecords = [484 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),485 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')486 ];487 ledgerRecords = [488 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', 'EUR', '', 2000, -10, 'IB', '', '', '', '', 'Kraken', '')489 ];490 validationError = new ValidationError(`Transfer row 3: Debit fee must be greater than or equal to 0 (or blank) when debit asset is specified.`, 3, 'debitFee');491 testValidateLedger('Transfer fiat negative debit fee', assetRecords, ledgerRecords, validationError);492 assetRecords = [493 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),494 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')495 ];496 ledgerRecords = [497 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', 'EUR', '', 2000, 0, 'IB', '', '', '', '', 'Kraken', '')498 ];499 validationError = null;500 testValidateLedger('Transfer fiat zero debit fee valid', assetRecords, ledgerRecords, validationError);501 assetRecords = [502 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),503 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')504 ];505 ledgerRecords = [506 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', 'EUR', '', 2000, '', '', '', '', '', '', 'Kraken', '')507 ];508 validationError = new ValidationError(`Transfer row 3: Debit wallet must be specified when debit asset is specified.`, 3, 'debitWalletName');509 testValidateLedger('Transfer fiat no debit wallet', assetRecords, ledgerRecords, validationError);510 assetRecords = [511 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),512 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')513 ];514 ledgerRecords = [515 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', 'EUR', '', 2000, '', 'IB', '', '', 2000, '', 'Kraken', '')516 ];517 validationError = new ValidationError(`Transfer row 3: Leave credit amount blank when credit asset is not specified.`, 3, 'creditAmount');518 testValidateLedger('Transfer fiat credit amount', assetRecords, ledgerRecords, validationError);519 assetRecords = [520 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),521 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')522 ];523 ledgerRecords = [524 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', 'EUR', '', 2000, '', 'IB', '', '', '', '', 'IB', '')525 ];526 validationError = new ValidationError(`Transfer row 3: Debit wallet (IB) and credit wallet (IB) must be different.`, 3, 'debitWalletName');527 testValidateLedger('Transfer fiat same debit and credit wallet', assetRecords, ledgerRecords, validationError);528 assetRecords = [529 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),530 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')531 ];532 ledgerRecords = [533 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'Kraken', 'ADA', '', 2000, '', '', ''),534 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', 'ADA', '', '', '', 'Kraken', '', '', '', '', 'Ledger', '')535 ];536 validationError = new ValidationError(`Transfer row 4: Debit amount must be specified when debit asset is specified.`, 4, 'debitAmount');537 testValidateLedger('Transfer asset no debit amount', assetRecords, ledgerRecords, validationError);538 assetRecords = [539 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),540 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')541 ];542 ledgerRecords = [543 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'Kraken', 'ADA', '', 2000, '', '', ''),544 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', 'ADA', '', -2000, '', 'Kraken', '', '', '', '', 'Ledger', '')545 ];546 validationError = new ValidationError(`Transfer row 4: Debit amount must be greater than 0 when debit asset is specified.`, 4, 'debitAmount');547 testValidateLedger('Transfer asset negative debit amount', assetRecords, ledgerRecords, validationError);548 assetRecords = [549 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),550 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')551 ];552 ledgerRecords = [553 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'Kraken', 'ADA', '', 2000, '', '', ''),554 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', 'ADA', '', 0, '', 'Kraken', '', '', '', '', 'Ledger', '')555 ];556 validationError = new ValidationError(`Transfer row 4: Debit amount must be greater than 0 when debit asset is specified.`, 4, 'debitAmount');557 testValidateLedger('Transfer asset zero debit amount', assetRecords, ledgerRecords, validationError);558 assetRecords = [559 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),560 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')561 ];562 ledgerRecords = [563 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'Kraken', 'ADA', '', 2000, '', '', ''),564 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', 'ADA', '', 2000, -10, 'Kraken', '', '', '', '', 'Ledger', '')565 ];566 validationError = new ValidationError(`Transfer row 4: Debit fee must be greater than or equal to 0 (or blank) when debit asset is specified.`, 4, 'debitFee');567 testValidateLedger('Transfer asset negative debit fee', assetRecords, ledgerRecords, validationError);568 assetRecords = [569 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),570 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')571 ];572 ledgerRecords = [573 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'Kraken', 'ADA', '', 2000, '', '', ''),574 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', 'ADA', '', 2000, 0, 'Kraken', '', '', '', '', 'Ledger', '')575 ];576 validationError = null;577 testValidateLedger('Transfer asset zero debit fee valid', assetRecords, ledgerRecords, validationError);578 assetRecords = [579 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),580 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')581 ];582 ledgerRecords = [583 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'Kraken', 'ADA', '', 2000, '', '', ''),584 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', 'ADA', '', 2000, '', '', '', '', '', '', 'Ledger', '')585 ];586 validationError = new ValidationError(`Transfer row 4: Debit wallet must be specified when debit asset is specified.`, 4, 'debitWalletName');587 testValidateLedger('Transfer asset no debit wallet', assetRecords, ledgerRecords, validationError);588 assetRecords = [589 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),590 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')591 ];592 ledgerRecords = [593 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'Kraken', 'ADA', '', 2000, '', '', ''),594 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', 'ADA', '', 2000, '', 'Kraken', '', '', 2000, '', 'Ledger', '')595 ];596 validationError = new ValidationError(`Transfer row 4: Leave credit amount blank when credit asset is not specified.`, 4, 'creditAmount');597 testValidateLedger('Transfer asset credit amount', assetRecords, ledgerRecords, validationError);598 assetRecords = [599 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),600 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')601 ];602 ledgerRecords = [603 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'Kraken', 'ADA', '', 2000, '', '', ''),604 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', 'ADA', '', 2000, '', 'Kraken', '', '', '', '', '', '')605 ];606 validationError = new ValidationError(`Transfer row 4: Credit wallet must be specified when debit asset is not fiat.`, 4, 'creditWalletName');607 testValidateLedger('Transfer asset no credit wallet', assetRecords, ledgerRecords, validationError);608 assetRecords = [609 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),610 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')611 ];612 ledgerRecords = [613 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'Kraken', 'ADA', '', 2000, '', '', ''),614 new LedgerRecord(new Date(2020, 3, 1), 'Transfer', 'ADA', '', 2000, '', 'Kraken', '', '', '', '', 'Kraken', '')615 ];616 validationError = new ValidationError(`Transfer row 4: Debit wallet (Kraken) and credit wallet (Kraken) must be different.`, 4, 'debitWalletName');617 testValidateLedger('Transfer asset same debit and credit wallet', assetRecords, ledgerRecords, validationError);618}619function validateLedgerTrade() {620 QUnit.module('Validate Ledger Trade');621 let assetRecords;622 let ledgerRecords;623 let validationError;624 assetRecords = [625 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),626 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')627 ];628 ledgerRecords = [629 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, 10, 'Kraken', 'ADA', '', 1000, 10, '', '')630 ];631 validationError = null;632 testValidateLedger('Trade fiat base buy with fees valid', assetRecords, ledgerRecords, validationError);633 assetRecords = [634 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),635 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')636 ];637 ledgerRecords = [638 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', '')639 ];640 validationError = null;641 testValidateLedger('Trade fiat base buy no fees valid', assetRecords, ledgerRecords, validationError);642 assetRecords = [643 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),644 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')645 ];646 ledgerRecords = [647 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, 10, 'Kraken', 'ADA', '', 1020, 10, '', ''),648 new LedgerRecord(new Date(2020, 3, 2), 'Trade', 'ADA', '', 1000, 10, 'Kraken', 'USD', '', 1200, 10, '', '')649 ];650 validationError = null;651 testValidateLedger('Trade fiat base sell with fees valid', assetRecords, ledgerRecords, validationError);652 assetRecords = [653 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),654 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')655 ];656 ledgerRecords = [657 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),658 new LedgerRecord(new Date(2020, 3, 2), 'Trade', 'ADA', '', 1000, '', 'Kraken', 'USD', '', 1200, '', '', '')659 ];660 validationError = null;661 testValidateLedger('Trade fiat base sell no fees valid', assetRecords, ledgerRecords, validationError);662 assetRecords = [663 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),664 new AssetRecord('EUR', 'Fiat', 2, 1, '', '', ''),665 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')666 ];667 ledgerRecords = [668 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'EUR', 1.2, 1200, 10, 'Kraken', 'ADA', '', 1000, 10, '', '')669 ];670 validationError = null;671 testValidateLedger('Trade fiat buy with fees debit exrate valid', assetRecords, ledgerRecords, validationError);672 assetRecords = [673 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),674 new AssetRecord('EUR', 'Fiat', 2, 1, '', '', ''),675 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')676 ];677 ledgerRecords = [678 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'EUR', 1.2, 1200, '', 'Kraken', 'ADA', '', 1000, '', '', '')679 ];680 validationError = null;681 testValidateLedger('Trade fiat buy no fees debit exrate valid', assetRecords, ledgerRecords, validationError);682 assetRecords = [683 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),684 new AssetRecord('EUR', 'Fiat', 2, 1, '', '', ''),685 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')686 ];687 ledgerRecords = [688 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'EUR', '', 1200, '', 'Kraken', 'ADA', 1.2, 1010, '', '', ''),689 new LedgerRecord(new Date(2020, 3, 2), 'Trade', 'ADA', 1.2, 1000, 10, 'Kraken', 'EUR', '', 1200, 10, '', '')690 ];691 validationError = null;692 testValidateLedger('Trade fiat sell with fees debit exrate valid', assetRecords, ledgerRecords, validationError);693 assetRecords = [694 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),695 new AssetRecord('EUR', 'Fiat', 2, 1, '', '', ''),696 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')697 ];698 ledgerRecords = [699 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'EUR', '', 1200, '', 'Kraken', 'ADA', 1.2, 1000, '', '', ''),700 new LedgerRecord(new Date(2020, 3, 2), 'Trade', 'ADA', 1.2, 1000, '', 'Kraken', 'EUR', '', 1200, '', '', '')701 ];702 validationError = null;703 testValidateLedger('Trade fiat sell no fees debit exrate valid', assetRecords, ledgerRecords, validationError);704 assetRecords = [705 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),706 new AssetRecord('EUR', 'Fiat', 2, 1, '', '', ''),707 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')708 ];709 ledgerRecords = [710 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'EUR', '', 1200, 10, 'Kraken', 'ADA', 1.2, 1000, 10, '', '')711 ];712 validationError = null;713 testValidateLedger('Trade fiat buy with fees credit exrate valid', assetRecords, ledgerRecords, validationError);714 assetRecords = [715 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),716 new AssetRecord('EUR', 'Fiat', 2, 1, '', '', ''),717 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')718 ];719 ledgerRecords = [720 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'EUR', '', 1200, '', 'Kraken', 'ADA', 1.2, 1000, '', '', '')721 ];722 validationError = null;723 testValidateLedger('Trade fiat buy no fees credit exrate valid', assetRecords, ledgerRecords, validationError);724 assetRecords = [725 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),726 new AssetRecord('EUR', 'Fiat', 2, 1, '', '', ''),727 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')728 ];729 ledgerRecords = [730 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'EUR', 1.2, 1200, '', 'Kraken', 'ADA', '', 1010, '', '', ''),731 new LedgerRecord(new Date(2020, 3, 2), 'Trade', 'ADA', '', 1000, 10, 'Kraken', 'EUR', 1.2, 1200, 10, '', '')732 ];733 validationError = null;734 testValidateLedger('Trade fiat sell with fees credit exrate valid', assetRecords, ledgerRecords, validationError);735 assetRecords = [736 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),737 new AssetRecord('EUR', 'Fiat', 2, 1, '', '', ''),738 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')739 ];740 ledgerRecords = [741 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'EUR', 1.2, 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),742 new LedgerRecord(new Date(2020, 3, 2), 'Trade', 'ADA', '', 1000, '', 'Kraken', 'EUR', 1.2, 1200, '', '', '')743 ];744 validationError = null;745 testValidateLedger('Trade fiat sell no fees credit exrate valid', assetRecords, ledgerRecords, validationError);746 assetRecords = [747 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),748 new AssetRecord('ADA', 'Crypto', 6, '', '', '', ''),749 new AssetRecord('ALGO', 'Crypto', 8, '', '', '', '')750 ];751 ledgerRecords = [752 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1010, '', '', ''),753 new LedgerRecord(new Date(2020, 3, 2), 'Trade', 'ADA', 1.2, 1000, 10, 'Kraken', 'ALGO', '', 1200, 10, '', '')754 ];755 validationError = null;756 testValidateLedger('Trade exchange assets with fees debit exrate valid', assetRecords, ledgerRecords, validationError);757 assetRecords = [758 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),759 new AssetRecord('ADA', 'Crypto', 6, '', '', '', ''),760 new AssetRecord('ALGO', 'Crypto', 8, '', '', '', '')761 ];762 ledgerRecords = [763 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),764 new LedgerRecord(new Date(2020, 3, 2), 'Trade', 'ADA', 1.2, 1000, '', 'Kraken', 'ALGO', '', 1200, '', '', '')765 ];766 validationError = null;767 testValidateLedger('Trade exchange assets no fees debit exrate valid', assetRecords, ledgerRecords, validationError);768 assetRecords = [769 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),770 new AssetRecord('ADA', 'Crypto', 6, '', '', '', ''),771 new AssetRecord('ALGO', 'Crypto', 8, '', '', '', '')772 ];773 ledgerRecords = [774 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1010, '', '', ''),775 new LedgerRecord(new Date(2020, 3, 2), 'Trade', 'ADA', '', 1000, 10, 'Kraken', 'ALGO', 1.2, 1200, 10, '', '')776 ];777 validationError = null;778 testValidateLedger('Trade exchange assets with fees credit exrate valid', assetRecords, ledgerRecords, validationError);779 assetRecords = [780 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),781 new AssetRecord('ADA', 'Crypto', 6, '', '', '', ''),782 new AssetRecord('ALGO', 'Crypto', 8, '', '', '', '')783 ];784 ledgerRecords = [785 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),786 new LedgerRecord(new Date(2020, 3, 2), 'Trade', 'ADA', '', 1000, '', 'Kraken', 'ALGO', 1.2, 1200, '', '', '')787 ];788 validationError = null;789 testValidateLedger('Trade exchange assets no fees credit exrate valid', assetRecords, ledgerRecords, validationError);790 assetRecords = [791 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),792 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')793 ];794 ledgerRecords = [795 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, 10, 'Kraken', 'EUR', '', 1000, 10, '', '')796 ];797 validationError = null;798 testValidateLedger('Trade fiat base buy fiat with fees valid', assetRecords, ledgerRecords, validationError);799 assetRecords = [800 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),801 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')802 ];803 ledgerRecords = [804 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'EUR', '', 1000, '', '', '')805 ];806 validationError = null;807 testValidateLedger('Trade fiat base buy fiat no fees valid', assetRecords, ledgerRecords, validationError);808 assetRecords = [809 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),810 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')811 ];812 ledgerRecords = [813 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'EUR', '', 1000, 10, 'Kraken', 'USD', '', 1200, 10, '', '')814 ];815 validationError = null;816 testValidateLedger('Trade fiat base sell fiat with fees valid', assetRecords, ledgerRecords, validationError);817 assetRecords = [818 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),819 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')820 ];821 ledgerRecords = [822 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'EUR', '', 1000, '', 'Kraken', 'USD', '', 1200, '', '', '')823 ];824 validationError = null;825 testValidateLedger('Trade fiat base sell fiat no fees valid', assetRecords, ledgerRecords, validationError);826 assetRecords = [827 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),828 new AssetRecord('EUR', 'Fiat', 2, '', '', '', ''),829 new AssetRecord('GBP', 'Fiat', 2, '', '', '', '')830 ];831 ledgerRecords = [832 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'GBP', '', 1000, 10, 'Kraken', 'EUR', '', 1200, 10, '', '')833 ];834 validationError = null;835 testValidateLedger('Trade exchange fiat with fees valid', assetRecords, ledgerRecords, validationError);836 assetRecords = [837 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),838 new AssetRecord('EUR', 'Fiat', 2, '', '', '', ''),839 new AssetRecord('GBP', 'Fiat', 2, '', '', '', '')840 ];841 ledgerRecords = [842 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'GBP', '', 1000, '', 'Kraken', 'EUR', '', 1200, '', '', '')843 ];844 validationError = null;845 testValidateLedger('Trade exchange fiat no fees valid', assetRecords, ledgerRecords, validationError);846 assetRecords = [847 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),848 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')849 ];850 ledgerRecords = [851 new LedgerRecord(new Date(2020, 3, 1), 'Trade', '', '', 2000, '', 'IB', 'LMN', '', 1000, '', '', '')852 ];853 validationError = new ValidationError(`Trade row 3: No debit asset specified.`, 3, 'debitAsset');854 testValidateLedger('Trade no debit asset', assetRecords, ledgerRecords, validationError);855 assetRecords = [856 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),857 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')858 ];859 ledgerRecords = [860 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', '', '', 1000, '', '', '')861 ];862 validationError = new ValidationError(`Trade row 3: No credit asset specified.`, 3, 'creditAsset');863 testValidateLedger('Trade no credit asset', assetRecords, ledgerRecords, validationError);864 assetRecords = [865 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),866 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')867 ];868 ledgerRecords = [869 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'LMN', '', 2000, '', 'IB', 'LMN', '', 1000, '', '', '')870 ];871 validationError = new ValidationError(`Trade row 3: Debit asset (LMN) and credit asset (LMN) must be different.`, 3, 'debitAsset');872 testValidateLedger('Trade same debit and credit asset', assetRecords, ledgerRecords, validationError);873 assetRecords = [874 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),875 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')876 ];877 ledgerRecords = [878 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', '', '', 'IB', 'LMN', '', 1000, '', '', '')879 ];880 validationError = new ValidationError(`Trade row 3: No debit amount specified.`, 3, 'debitAmount');881 testValidateLedger('Trade no debit amount', assetRecords, ledgerRecords, validationError);882 assetRecords = [883 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),884 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')885 ];886 ledgerRecords = [887 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', -2000, '', 'IB', 'LMN', '', 1000, '', '', '')888 ];889 validationError = new ValidationError(`Trade row 3: Debit amount must be greater than or equal to 0.`, 3, 'debitAmount');890 testValidateLedger('Trade negative debit amount', assetRecords, ledgerRecords, validationError);891 assetRecords = [892 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),893 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')894 ];895 ledgerRecords = [896 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 0, '', 'IB', 'LMN', '', 1000, '', '', '')897 ];898 validationError = null;899 testValidateLedger('Trade zero debit amount valid', assetRecords, ledgerRecords, validationError);900 assetRecords = [901 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),902 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')903 ];904 ledgerRecords = [905 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, -10, 'IB', 'LMN', '', 1000, '', '', '')906 ];907 validationError = new ValidationError(`Trade row 3: Debit fee must be greater than or equal to 0 (or blank).`, 3, 'debitFee');908 testValidateLedger('Trade negative debit fee', assetRecords, ledgerRecords, validationError);909 assetRecords = [910 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),911 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')912 ];913 ledgerRecords = [914 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, 0, 'IB', 'LMN', '', 1000, '', '', '')915 ];916 validationError = null;917 testValidateLedger('Trade zero debit fee valid', assetRecords, ledgerRecords, validationError);918 assetRecords = [919 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),920 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')921 ];922 ledgerRecords = [923 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', '', 'LMN', '', 1000, '', '', '')924 ];925 validationError = new ValidationError(`Trade row 3: No debit wallet specified.`, 3, 'debitWalletName');926 testValidateLedger('Trade no debit wallet', assetRecords, ledgerRecords, validationError);927 assetRecords = [928 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),929 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')930 ];931 ledgerRecords = [932 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', '', '', '', '')933 ];934 validationError = new ValidationError(`Trade row 3: No credit amount specified.`, 3, 'creditAmount');935 testValidateLedger('Trade no credit amount', assetRecords, ledgerRecords, validationError);936 assetRecords = [937 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),938 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')939 ];940 ledgerRecords = [941 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', -1000, '', '', '')942 ];943 validationError = new ValidationError(`Trade row 3: Credit amount must be greater than or equal to 0.`, 3, 'creditAmount');944 testValidateLedger('Trade negative credit amount', assetRecords, ledgerRecords, validationError);945 assetRecords = [946 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),947 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')948 ];949 ledgerRecords = [950 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 0, '', '', '')951 ];952 validationError = null;953 testValidateLedger('Trade zero credit amount valid', assetRecords, ledgerRecords, validationError);954 assetRecords = [955 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),956 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')957 ];958 ledgerRecords = [959 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, -10, '', '')960 ];961 validationError = new ValidationError(`Trade row 3: Credit fee must be greater than or equal to 0 (or blank).`, 3, 'creditFee');962 testValidateLedger('Trade negative credit fee', assetRecords, ledgerRecords, validationError);963 assetRecords = [964 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),965 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')966 ];967 ledgerRecords = [968 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 1001, '', '')969 ];970 validationError = new ValidationError(`Trade row 3: Credit fee must be less than or equal to credit amount (or blank).`, 3, 'creditFee');971 testValidateLedger('Trade Credit fee greater than credit amount', assetRecords, ledgerRecords, validationError);972 assetRecords = [973 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),974 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')975 ];976 ledgerRecords = [977 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 1000, '', '')978 ];979 validationError = null;980 testValidateLedger('Trade asset credit fee same as credit amount valid', assetRecords, ledgerRecords, validationError);981 assetRecords = [982 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),983 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')984 ];985 ledgerRecords = [986 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, '', 'Fidelity', '')987 ];988 validationError = new ValidationError(`Trade row 3: Leave credit wallet (Fidelity) blank. It is inferred from the debit wallet (IB).`, 3, 'creditWalletName');989 testValidateLedger('Trade credit wallet', assetRecords, ledgerRecords, validationError);990 assetRecords = [991 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),992 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')993 ];994 ledgerRecords = [995 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', 1, 2000, '', 'IB', 'LMN', '', 1000, '', '', '')996 ];997 validationError = new ValidationError(`Trade row 3: Debit asset is fiat base (USD). Leave debit exchange rate blank.`, 3, 'debitExRate');998 testValidateLedger('Trade debit asset is fiat base and debit exrate', assetRecords, ledgerRecords, validationError);999 assetRecords = [1000 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1001 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')1002 ];1003 ledgerRecords = [1004 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', 1, 1000, '', '', '')1005 ];1006 validationError = new ValidationError(`Trade row 3: Debit asset is fiat base (USD). Leave credit exchange rate blank.`, 3, 'creditExRate');1007 testValidateLedger('Trade debit asset is fiat base and credit exrate', assetRecords, ledgerRecords, validationError);1008 assetRecords = [1009 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1010 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')1011 ];1012 ledgerRecords = [1013 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, '', '', ''),1014 new LedgerRecord(new Date(2020, 3, 2), 'Trade', 'LMN', 1, 200, '', 'IB', 'USD', '', 600, '', '', '')1015 ];1016 validationError = new ValidationError(`Trade row 4: Credit asset is fiat base (USD). Leave debit exchange rate blank.`, 4, 'debitExRate');1017 testValidateLedger('Trade credit asset is fiat base and debit exrate', assetRecords, ledgerRecords, validationError);1018 assetRecords = [1019 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1020 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')1021 ];1022 ledgerRecords = [1023 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, '', '', ''),1024 new LedgerRecord(new Date(2020, 3, 2), 'Trade', 'LMN', '', 200, '', 'IB', 'USD', 1, 600, '', '', '')1025 ];1026 validationError = new ValidationError(`Trade row 4: Credit asset is fiat base (USD). Leave credit exchange rate blank.`, 4, 'creditExRate');1027 testValidateLedger('Trade credit asset is fiat base and credit exrate', assetRecords, ledgerRecords, validationError);1028 assetRecords = [1029 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1030 new AssetRecord('EUR', 'Fiat', 2, '', '', '', ''),1031 new AssetRecord('GBP', 'Fiat', 2, '', '', '', '')1032 ];1033 ledgerRecords = [1034 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'GBP', 1.2, 1000, '', 'IB', 'EUR', '', 1200, '', '', '')1035 ];1036 validationError = new ValidationError(`Trade row 3: Fiat exchange: (GBP/EUR). Leave debit exchange rate blank.`, 3, 'debitExRate');1037 testValidateLedger('Trade fiat exchange and debit exrate', assetRecords, ledgerRecords, validationError);1038 assetRecords = [1039 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1040 new AssetRecord('EUR', 'Fiat', 2, '', '', '', ''),1041 new AssetRecord('GBP', 'Fiat', 2, '', '', '', '')1042 ];1043 ledgerRecords = [1044 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'EUR', '', 1200, '', 'IB', 'GBP', 1.2, 1000, '', '', '')1045 ];1046 validationError = new ValidationError(`Trade row 3: Fiat exchange: (EUR/GBP). Leave credit exchange rate blank.`, 3, 'creditExRate');1047 testValidateLedger('Trade fiat exchange and credit exrate', assetRecords, ledgerRecords, validationError);1048 assetRecords = [1049 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1050 new AssetRecord('EUR', 'Fiat', 2, '', '', '', ''),1051 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')1052 ];1053 ledgerRecords = [1054 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'EUR', 1.2, 0, '', 'IB', 'LMN', '', 1000, '', '', '')1055 ];1056 validationError = new ValidationError(`Trade row 3: Trade with zero debit amount. Leave debit exchange rate blank.`, 3, 'debitExRate');1057 testValidateLedger('Trade non fiat base non fiat-fiat zero debit amount and debit exrate', assetRecords, ledgerRecords, validationError);1058 assetRecords = [1059 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1060 new AssetRecord('EUR', 'Fiat', 2, '', '', '', ''),1061 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')1062 ];1063 ledgerRecords = [1064 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'EUR', '', 0, '', 'IB', 'LMN', 2.4, 1000, '', '', '')1065 ];1066 validationError = new ValidationError(`Trade row 3: Trade with zero debit amount. Leave credit exchange rate blank.`, 3, 'creditExRate');1067 testValidateLedger('Trade non fiat base non fiat-fiat zero debit amount and credit exrate', assetRecords, ledgerRecords, validationError);1068 assetRecords = [1069 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1070 new AssetRecord('EUR', 'Fiat', 2, '', '', '', ''),1071 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')1072 ];1073 ledgerRecords = [1074 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'EUR', 1.2, 2000, '', 'IB', 'LMN', '', 0, '', '', '')1075 ];1076 validationError = new ValidationError(`Trade row 3: Trade with zero credit amount. Leave debit exchange rate blank.`, 3, 'debitExRate');1077 testValidateLedger('Trade non fiat base non fiat-fiat zero credit amount and debit exrate', assetRecords, ledgerRecords, validationError);1078 assetRecords = [1079 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1080 new AssetRecord('EUR', 'Fiat', 2, '', '', '', ''),1081 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')1082 ];1083 ledgerRecords = [1084 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'EUR', '', 2000, '', 'IB', 'LMN', 2.4, 0, '', '', '')1085 ];1086 validationError = new ValidationError(`Trade row 3: Trade with zero credit amount. Leave credit exchange rate blank.`, 3, 'creditExRate');1087 testValidateLedger('Trade non fiat base non fiat-fiat zero credit amount and credit exrate', assetRecords, ledgerRecords, validationError);1088 assetRecords = [1089 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1090 new AssetRecord('EUR', 'Fiat', 2, '', '', '', ''),1091 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')1092 ];1093 ledgerRecords = [1094 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'EUR', '', 2000, '', 'IB', 'LMN', '', 1000, '', '', '')1095 ];1096 validationError = new ValidationError(`Trade row 3: Non fiat base trade requires either debit asset (EUR) or credit asset (LMN) to fiat base (USD) exchange rate.`, 3, 'debitExRate');1097 testValidateLedger('Trade non fiat base non fiat-fiat and no debit or credit exrate', assetRecords, ledgerRecords, validationError);1098 assetRecords = [1099 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1100 new AssetRecord('EUR', 'Fiat', 2, '', '', '', ''),1101 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')1102 ];1103 ledgerRecords = [1104 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'EUR', 1.2, 2000, '', 'IB', 'LMN', 2.4, 1000, '', '', '')1105 ];1106 validationError = new ValidationError(`Trade row 3: Remove one of the exchange rates.\n\nNon fiat base trade requires either debit asset (EUR) or credit asset (LMN) to fiat base (USD) exchange rate, but not both. One exchange rate can be deduced from the other and the amounts of assets exchanged. The exchange rate of the least volatile, most widely traded asset is likely to be more accurate.`, 3, 'debitExRate');1107 testValidateLedger('Trade non fiat base non fiat-fiat and both debit and credit exrate', assetRecords, ledgerRecords, validationError);1108 assetRecords = [1109 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1110 new AssetRecord('EUR', 'Fiat', 2, '', '', '', ''),1111 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')1112 ];1113 ledgerRecords = [1114 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'EUR', -1.2, 2000, '', 'IB', 'LMN', '', 1000, '', '', '')1115 ];1116 validationError = new ValidationError(`Trade row 3: Debit exchange rate must be greater than or equal to 0.`, 3, 'debitExRate');1117 testValidateLedger('Trade non fiat base non fiat-fiat and negative debit exrate', assetRecords, ledgerRecords, validationError);1118 assetRecords = [1119 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1120 new AssetRecord('EUR', 'Fiat', 2, '', '', '', ''),1121 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')1122 ];1123 ledgerRecords = [1124 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'EUR', 0, 2000, '', 'IB', 'LMN', '', 1000, '', '', '')1125 ];1126 validationError = null;1127 testValidateLedger('Trade non fiat base non fiat-fiat and zero debit exrate valid', assetRecords, ledgerRecords, validationError);1128 assetRecords = [1129 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1130 new AssetRecord('EUR', 'Fiat', 2, '', '', '', ''),1131 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')1132 ];1133 ledgerRecords = [1134 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'EUR', '', 2000, '', 'IB', 'LMN', -2.4, 1000, '', '', '')1135 ];1136 validationError = new ValidationError(`Trade row 3: Credit exchange rate must be greater than or equal to 0.`, 3, 'creditExRate');1137 testValidateLedger('Trade non fiat base non fiat-fiat and negative credit exrate', assetRecords, ledgerRecords, validationError);1138 assetRecords = [1139 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1140 new AssetRecord('EUR', 'Fiat', 2, '', '', '', ''),1141 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')1142 ];1143 ledgerRecords = [1144 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'EUR', '', 2000, '', 'IB', 'LMN', 0, 1000, '', '', '')1145 ];1146 validationError = null;1147 testValidateLedger('Trade non fiat base non fiat-fiat and zero credit exrate valid', assetRecords, ledgerRecords, validationError);1148}1149function validateLedgerIncome() {1150 QUnit.module('Validate Ledger Income');1151 let assetRecords;1152 let ledgerRecords;1153 let validationError;1154 assetRecords = [1155 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1156 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1157 ];1158 ledgerRecords = [1159 new LedgerRecord(new Date(2020, 3, 1), 'Income', '', '', '', '', '', 'ADA', 1.2, 1000, '', 'Ledger', '')1160 ];1161 validationError = null;1162 testValidateLedger('Income rewards valid', assetRecords, ledgerRecords, validationError);1163 assetRecords = [1164 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1165 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')1166 ];1167 ledgerRecords = [1168 new LedgerRecord(new Date(2020, 3, 1), 'Income', '', '', '', '', '', 'EUR', 1.2, 1000, '', 'IB', '')1169 ];1170 validationError = null;1171 testValidateLedger('Income fiat interest valid', assetRecords, ledgerRecords, validationError);1172 assetRecords = [1173 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', '')1174 ];1175 ledgerRecords = [1176 new LedgerRecord(new Date(2020, 3, 1), 'Income', '', '', '', '', '', 'USD', '', 1000, '', 'IB', '')1177 ];1178 validationError = null;1179 testValidateLedger('Income fiat base interest valid', assetRecords, ledgerRecords, validationError);1180 assetRecords = [1181 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1182 new AssetRecord('EUR', 'Fiat', 2, '', '', '', ''),1183 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')1184 ];1185 ledgerRecords = [1186 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'EUR', 1.2, 2000, '', 'IB', 'LMN', '', 1000, '', '', ''),1187 new LedgerRecord(new Date(2020, 3, 2), 'Trade', 'LMN', '', 1000, '', 'IB', 'EUR', 1.2, 2000, '', '', ''),1188 new LedgerRecord(new Date(2020, 3, 3), 'Income', 'LMN', '', '', '', '', 'EUR', 1.2, 1000, '', 'IB', '')1189 ];1190 validationError = null;1191 testValidateLedger('Income fiat dividend valid', assetRecords, ledgerRecords, validationError);1192 assetRecords = [1193 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1194 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')1195 ];1196 ledgerRecords = [1197 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, '', '', ''),1198 new LedgerRecord(new Date(2020, 3, 2), 'Trade', 'LMN', '', 1000, '', 'IB', 'USD', '', 2000, '', '', ''),1199 new LedgerRecord(new Date(2020, 3, 3), 'Income', 'LMN', '', '', '', '', 'USD', '', 1000, '', 'IB', '')1200 ];1201 validationError = null;1202 testValidateLedger('Income fiat base dividend valid', assetRecords, ledgerRecords, validationError);1203 assetRecords = [1204 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1205 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1206 ];1207 ledgerRecords = [1208 new LedgerRecord(new Date(2020, 3, 1), 'Income', '', 1.2, '', '', '', 'ADA', 1.2, 1000, '', 'Ledger', '')1209 ];1210 validationError = new ValidationError(`Income row 3: Leave debit exchange rate blank.`, 3, 'debitExRate');1211 testValidateLedger('Income debit exrate', assetRecords, ledgerRecords, validationError);1212 assetRecords = [1213 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1214 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1215 ];1216 ledgerRecords = [1217 new LedgerRecord(new Date(2020, 3, 1), 'Income', '', '', 1000, '', '', 'ADA', 1.2, 1000, '', 'Ledger', '')1218 ];1219 validationError = new ValidationError(`Income row 3: Leave debit amount blank.`, 3, 'debitAmount');1220 testValidateLedger('Income debit amount', assetRecords, ledgerRecords, validationError);1221 assetRecords = [1222 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1223 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1224 ];1225 ledgerRecords = [1226 new LedgerRecord(new Date(2020, 3, 1), 'Income', '', '', '', 10, '', 'ADA', 1.2, 1000, '', 'Ledger', '')1227 ];1228 validationError = new ValidationError(`Income row 3: Leave debit fee blank.`, 3, 'debitFee');1229 testValidateLedger('Income debit fee', assetRecords, ledgerRecords, validationError);1230 assetRecords = [1231 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1232 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1233 ];1234 ledgerRecords = [1235 new LedgerRecord(new Date(2020, 3, 1), 'Income', '', '', '', '', 'IB', 'ADA', 1.2, 1000, '', 'Ledger', '')1236 ];1237 validationError = new ValidationError(`Income row 3: Leave debit wallet (IB) blank.`, 3, 'debitWalletName');1238 testValidateLedger('Income debit wallet', assetRecords, ledgerRecords, validationError);1239 assetRecords = [1240 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1241 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1242 ];1243 ledgerRecords = [1244 new LedgerRecord(new Date(2020, 3, 1), 'Income', '', '', '', '', '', '', 1.2, 1000, '', 'Ledger', '')1245 ];1246 validationError = new ValidationError(`Income row 3: No credit asset specified.`, 3, 'creditAsset');1247 testValidateLedger('Income no credit asset', assetRecords, ledgerRecords, validationError);1248 assetRecords = [1249 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1250 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')1251 ];1252 ledgerRecords = [1253 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, '', '', ''),1254 new LedgerRecord(new Date(2020, 3, 2), 'Trade', 'LMN', '', 1000, '', 'IB', 'USD', '', 2000, '', '', ''),1255 new LedgerRecord(new Date(2020, 3, 3), 'Income', 'LMN', '', '', '', '', 'USD', 1.2, 1000, '', 'Ledger', '')1256 ];1257 validationError = new ValidationError(`Income row 5: Leave credit exchange rate blank when credit asset is fiat base (USD).`, 5, 'creditExRate');1258 testValidateLedger('Income credit asset is fiat base and credit exrate', assetRecords, ledgerRecords, validationError);1259 assetRecords = [1260 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1261 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1262 ];1263 ledgerRecords = [1264 new LedgerRecord(new Date(2020, 3, 1), 'Income', '', '', '', '', '', 'ADA', '', 1000, '', 'Ledger', '')1265 ];1266 validationError = new ValidationError(`Income row 3: Missing credit asset (ADA) to fiat base (USD) exchange rate.`, 3, 'creditExRate');1267 testValidateLedger('Income credit asset not fiat base and no credit exrate', assetRecords, ledgerRecords, validationError);1268 assetRecords = [1269 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1270 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1271 ];1272 ledgerRecords = [1273 new LedgerRecord(new Date(2020, 3, 1), 'Income', '', '', '', '', '', 'ADA', -1.2, 1000, '', 'Ledger', '')1274 ];1275 validationError = new ValidationError(`Income row 3: Credit exchange rate must be greater than or equal to 0.`, 3, 'creditExRate');1276 testValidateLedger('Income credit asset not fiat base and negative credit exrate', assetRecords, ledgerRecords, validationError);1277 assetRecords = [1278 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1279 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1280 ];1281 ledgerRecords = [1282 new LedgerRecord(new Date(2020, 3, 1), 'Income', '', '', '', '', '', 'ADA', 0, 1000, '', 'Ledger', '')1283 ];1284 validationError = null;1285 testValidateLedger('Income credit asset not fiat base and zero credit exrate valid', assetRecords, ledgerRecords, validationError);1286 assetRecords = [1287 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1288 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1289 ];1290 ledgerRecords = [1291 new LedgerRecord(new Date(2020, 3, 1), 'Income', '', '', '', '', '', 'ADA', 1.2, '', '', 'Ledger', '')1292 ];1293 validationError = new ValidationError(`Income row 3: No credit amount specified.`, 3, 'creditAmount');1294 testValidateLedger('Income no credit amount', assetRecords, ledgerRecords, validationError);1295 assetRecords = [1296 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1297 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1298 ];1299 ledgerRecords = [1300 new LedgerRecord(new Date(2020, 3, 1), 'Income', '', '', '', '', '', 'ADA', 1.2, -1000, '', 'Ledger', '')1301 ];1302 validationError = new ValidationError(`Income row 3: Credit amount must be greater than 0.`, 3, 'creditAmount');1303 testValidateLedger('Income negative credit amount', assetRecords, ledgerRecords, validationError);1304 assetRecords = [1305 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1306 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1307 ];1308 ledgerRecords = [1309 new LedgerRecord(new Date(2020, 3, 1), 'Income', '', '', '', '', '', 'ADA', 1.2, 0, '', 'Ledger', '')1310 ];1311 validationError = new ValidationError(`Income row 3: Credit amount must be greater than 0.`, 3, 'creditAmount');1312 testValidateLedger('Income zero credit amount', assetRecords, ledgerRecords, validationError);1313 assetRecords = [1314 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1315 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1316 ];1317 ledgerRecords = [1318 new LedgerRecord(new Date(2020, 3, 1), 'Income', '', '', '', '', '', 'ADA', 1.2, 1000, 10, 'Ledger', '')1319 ];1320 validationError = new ValidationError(`Income row 3: Leave credit fee blank.`, 3, 'creditFee');1321 testValidateLedger('Income credit fee', assetRecords, ledgerRecords, validationError);1322 assetRecords = [1323 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1324 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1325 ];1326 ledgerRecords = [1327 new LedgerRecord(new Date(2020, 3, 1), 'Income', '', '', '', '', '', 'ADA', 1.2, 1000, '', '', '')1328 ];1329 validationError = new ValidationError(`Income row 3: No credit wallet specified.`, 3, 'creditWalletName');1330 testValidateLedger('Income no credit wallet', assetRecords, ledgerRecords, validationError);1331}1332function validateLedgerDonation() {1333 QUnit.module('Validate Ledger Donation');1334 let assetRecords;1335 let ledgerRecords;1336 let validationError;1337 assetRecords = [1338 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1339 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1340 ];1341 ledgerRecords = [1342 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1343 new LedgerRecord(new Date(2020, 3, 2), 'Donation', 'ADA', '1.2', 990, 10, 'Kraken', '', '', '', '', '', '')1344 ];1345 validationError = null;1346 testValidateLedger('Donation with fee valid', assetRecords, ledgerRecords, validationError);1347 assetRecords = [1348 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1349 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1350 ];1351 ledgerRecords = [1352 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1353 new LedgerRecord(new Date(2020, 3, 2), 'Donation', 'ADA', '1.2', 1000, '', 'Kraken', '', '', '', '', '', '')1354 ];1355 validationError = null;1356 testValidateLedger('Donation no fee valid', assetRecords, ledgerRecords, validationError);1357 assetRecords = [1358 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1359 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1360 ];1361 ledgerRecords = [1362 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1363 new LedgerRecord(new Date(2020, 3, 2), 'Donation', '', '1.2', 1000, '', 'Kraken', '', '', '', '', '', '')1364 ];1365 validationError = new ValidationError(`Donation row 4: No debit asset specified.`, 4, 'debitAsset');1366 testValidateLedger('Donation no debit asset', assetRecords, ledgerRecords, validationError);1367 assetRecords = [1368 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1369 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')1370 ];1371 ledgerRecords = [1372 new LedgerRecord(new Date(2020, 3, 2), 'Donation', 'EUR', '1.2', 1000, '', 'Kraken', '', '', '', '', '', '')1373 ];1374 validationError = new ValidationError(`Donation row 3: Debit asset (EUR) is fiat, not supported.`, 3, 'debitAsset');1375 testValidateLedger('Donation debit asset fiat', assetRecords, ledgerRecords, validationError);1376 assetRecords = [1377 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1378 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1379 ];1380 ledgerRecords = [1381 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1382 new LedgerRecord(new Date(2020, 3, 2), 'Donation', 'ADA', '', 1000, '', 'Kraken', '', '', '', '', '', '')1383 ];1384 validationError = new ValidationError(`Donation row 4: Missing debit asset (ADA) to fiat base (USD) exchange rate.`, 4, 'debitExRate');1385 testValidateLedger('Donation no debit exrate', assetRecords, ledgerRecords, validationError);1386 assetRecords = [1387 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1388 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1389 ];1390 ledgerRecords = [1391 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1392 new LedgerRecord(new Date(2020, 3, 2), 'Donation', 'ADA', -1.2, 1000, '', 'Kraken', '', '', '', '', '', '')1393 ];1394 validationError = new ValidationError(`Donation row 4: Debit exchange rate must be greater than or equal to 0.`, 4, 'debitExRate');1395 testValidateLedger('Donation negative debit exrate', assetRecords, ledgerRecords, validationError);1396 assetRecords = [1397 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1398 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1399 ];1400 ledgerRecords = [1401 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1402 new LedgerRecord(new Date(2020, 3, 2), 'Donation', 'ADA', 0, 1000, '', 'Kraken', '', '', '', '', '', '')1403 ];1404 validationError = null;1405 testValidateLedger('Donation zero debit exrate valid', assetRecords, ledgerRecords, validationError);1406 assetRecords = [1407 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1408 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1409 ];1410 ledgerRecords = [1411 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1412 new LedgerRecord(new Date(2020, 3, 2), 'Donation', 'ADA', 1.2, '', '', 'Kraken', '', '', '', '', '', '')1413 ];1414 validationError = new ValidationError(`Donation row 4: No debit amount specified.`, 4, 'debitAmount');1415 testValidateLedger('Donation no debit amount', assetRecords, ledgerRecords, validationError);1416 assetRecords = [1417 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1418 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1419 ];1420 ledgerRecords = [1421 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1422 new LedgerRecord(new Date(2020, 3, 2), 'Donation', 'ADA', 1.2, -1000, '', 'Kraken', '', '', '', '', '', '')1423 ];1424 validationError = new ValidationError(`Donation row 4: Debit amount must be greater than 0.`, 4, 'debitAmount');1425 testValidateLedger('Donation negative debit amount', assetRecords, ledgerRecords, validationError);1426 assetRecords = [1427 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1428 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1429 ];1430 ledgerRecords = [1431 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1432 new LedgerRecord(new Date(2020, 3, 2), 'Donation', 'ADA', 1.2, 0, '', 'Kraken', '', '', '', '', '', '')1433 ];1434 validationError = new ValidationError(`Donation row 4: Debit amount must be greater than 0.`, 4, 'debitAmount');1435 testValidateLedger('Donation zero debit amount', assetRecords, ledgerRecords, validationError);1436 assetRecords = [1437 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1438 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1439 ];1440 ledgerRecords = [1441 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1442 new LedgerRecord(new Date(2020, 3, 2), 'Donation', 'ADA', 1.2, 1000, -10, 'Kraken', '', '', '', '', '', '')1443 ];1444 validationError = new ValidationError(`Donation row 4: Debit fee must be greater than or equal to 0 (or blank).`, 4, 'debitFee');1445 testValidateLedger('Donation negative debit fee', assetRecords, ledgerRecords, validationError);1446 assetRecords = [1447 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1448 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1449 ];1450 ledgerRecords = [1451 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1452 new LedgerRecord(new Date(2020, 3, 2), 'Donation', 'ADA', 1.2, 1000, 0, 'Kraken', '', '', '', '', '', '')1453 ];1454 validationError = null;1455 testValidateLedger('Donation zero debit fee valid', assetRecords, ledgerRecords, validationError);1456 assetRecords = [1457 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1458 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1459 ];1460 ledgerRecords = [1461 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1462 new LedgerRecord(new Date(2020, 3, 2), 'Donation', 'ADA', 1.2, 1000, '', '', '', '', '', '', '', '')1463 ];1464 validationError = new ValidationError(`Donation row 4: No debit wallet specified.`, 4, 'debitWalletName');1465 testValidateLedger('Donation no debit wallet', assetRecords, ledgerRecords, validationError);1466 assetRecords = [1467 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1468 new AssetRecord('ADA', 'Crypto', 6, '', '', '', ''),1469 new AssetRecord('BTC', 'Crypto', 8, '', '', '', '')1470 ];1471 ledgerRecords = [1472 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1473 new LedgerRecord(new Date(2020, 3, 2), 'Donation', 'ADA', 1.2, 1000, '', 'Kraken', 'BTC', '', '', '', '', '')1474 ];1475 validationError = new ValidationError(`Donation row 4: Leave credit asset (BTC) blank.`, 4, 'creditAsset');1476 testValidateLedger('Donation credit asset', assetRecords, ledgerRecords, validationError);1477 assetRecords = [1478 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1479 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1480 ];1481 ledgerRecords = [1482 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1483 new LedgerRecord(new Date(2020, 3, 2), 'Donation', 'ADA', 1.2, 1000, '', 'Kraken', '', 1.2, '', '', '', '')1484 ];1485 validationError = new ValidationError(`Donation row 4: Leave credit exchange rate blank.`, 4, 'creditExRate');1486 testValidateLedger('Donation credit exrate', assetRecords, ledgerRecords, validationError);1487 assetRecords = [1488 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1489 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1490 ];1491 ledgerRecords = [1492 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1493 new LedgerRecord(new Date(2020, 3, 2), 'Donation', 'ADA', 1.2, 1000, '', 'Kraken', '', '', 1000, '', '', '')1494 ];1495 validationError = new ValidationError(`Donation row 4: Leave credit amount blank.`, 4, 'creditAmount');1496 testValidateLedger('Donation credit amount', assetRecords, ledgerRecords, validationError);1497 assetRecords = [1498 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1499 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1500 ];1501 ledgerRecords = [1502 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1503 new LedgerRecord(new Date(2020, 3, 2), 'Donation', 'ADA', 1.2, 1000, '', 'Kraken', '', '', '', 10, '', '')1504 ];1505 validationError = new ValidationError(`Donation row 4: Leave credit fee blank.`, 4, 'creditFee');1506 testValidateLedger('Donation credit fee', assetRecords, ledgerRecords, validationError);1507 assetRecords = [1508 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1509 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1510 ];1511 ledgerRecords = [1512 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1513 new LedgerRecord(new Date(2020, 3, 2), 'Donation', 'ADA', 1.2, 1000, '', 'Kraken', '', '', '', '', 'IB', '')1514 ];1515 validationError = new ValidationError(`Donation row 4: Leave credit wallet (IB) blank.`, 4, 'creditWalletName');1516 testValidateLedger('Donation credit wallet', assetRecords, ledgerRecords, validationError);1517}1518function validateLedgerGift() {1519 QUnit.module('Validate Ledger Gift');1520 let assetRecords;1521 let ledgerRecords;1522 let validationError;1523 assetRecords = [1524 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1525 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1526 ];1527 ledgerRecords = [1528 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1010, '', '', ''),1529 new LedgerRecord(new Date(2020, 3, 2), 'Gift', 'ADA', 1.2, 1000, 10, 'Kraken', '', '', '', '', '', '')1530 ];1531 validationError = null;1532 testValidateLedger('Gift given with fee valid', assetRecords, ledgerRecords, validationError);1533 assetRecords = [1534 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1535 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1536 ];1537 ledgerRecords = [1538 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1539 new LedgerRecord(new Date(2020, 3, 2), 'Gift', 'ADA', 1.2, 1000, '', 'Kraken', '', '', '', '', '', '')1540 ];1541 validationError = null;1542 testValidateLedger('Gift given no fee valid', assetRecords, ledgerRecords, validationError);1543 assetRecords = [1544 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1545 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1546 ];1547 ledgerRecords = [1548 new LedgerRecord(new Date(2020, 3, 1), 'Gift', 'USD', '', 1200, '', '', 'ADA', '', 1000, '', 'Ledger', '')1549 ];1550 validationError = null;1551 testValidateLedger('Gift received valid', assetRecords, ledgerRecords, validationError);1552 assetRecords = [1553 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1554 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1555 ];1556 ledgerRecords = [1557 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1558 new LedgerRecord(new Date(2020, 3, 2), 'Gift', '', '', 1000, '', 'Kraken', '', '', '', '', '', '')1559 ];1560 validationError = new ValidationError(`Gift row 4: No debit asset specified.\n\nFor gifts given debit asset is the asset given.\n\nFor gifts received debit asset must be fiat base (USD) for the inherited cost basis.`, 4, 'debitAsset');1561 testValidateLedger('Gift no debit asset', assetRecords, ledgerRecords, validationError);1562 assetRecords = [1563 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1564 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1565 ];1566 ledgerRecords = [1567 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1568 new LedgerRecord(new Date(2020, 3, 2), 'Gift', 'ADA', '', 1000, '', '', '', '', '', '', '', '')1569 ];1570 validationError = new ValidationError(`Gift row 4: Either debit wallet (for gifts given) or credit wallet (for gifts received) must be specified.`, 4, 'debitWalletName');1571 testValidateLedger('Gift no debit or credit wallet', assetRecords, ledgerRecords, validationError);1572 assetRecords = [1573 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1574 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1575 ];1576 ledgerRecords = [1577 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1578 new LedgerRecord(new Date(2020, 3, 2), 'Gift', 'ADA', '', 1000, '', 'Kraken', '', '', '', '', 'IB', '')1579 ];1580 validationError = new ValidationError(`Gift row 4: Either debit wallet (for gifts given) or credit wallet (for gifts received) must be specified, but not both.`, 4, 'debitWalletName');1581 testValidateLedger('Gift both debit and credit wallet', assetRecords, ledgerRecords, validationError);1582 assetRecords = [1583 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1584 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1585 ];1586 ledgerRecords = [1587 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1588 new LedgerRecord(new Date(2020, 3, 2), 'Gift', 'ADA', 1.2, 1000, -10, 'Kraken', '', '', '', '', '', '')1589 ];1590 validationError = new ValidationError(`Gift row 4: Debit fee must be greater than or equal to 0 (or blank).`, 4, 'debitFee');1591 testValidateLedger('Gift negative debit fee', assetRecords, ledgerRecords, validationError);1592 assetRecords = [1593 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1594 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1595 ];1596 ledgerRecords = [1597 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1598 new LedgerRecord(new Date(2020, 3, 2), 'Gift', 'ADA', 1.2, 1000, 0, 'Kraken', '', '', '', '', '', '')1599 ];1600 validationError = null;1601 testValidateLedger('Gift zero debit fee valid', assetRecords, ledgerRecords, validationError);1602 assetRecords = [1603 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1604 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1605 ];1606 ledgerRecords = [1607 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1608 new LedgerRecord(new Date(2020, 3, 2), 'Gift', 'ADA', 1.2, 1000, '', 'Kraken', '', 1.2, '', '', '', '')1609 ];1610 validationError = new ValidationError(`Gift row 4: Leave credit exchange rate blank.`, 4, 'creditExRate');1611 testValidateLedger('Gift credit exrate', assetRecords, ledgerRecords, validationError);1612 assetRecords = [1613 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1614 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1615 ];1616 ledgerRecords = [1617 new LedgerRecord(new Date(2020, 3, 1), 'Gift', 'USD', '', 1200, '', '', 'ADA', '', 1000, 10, 'Ledger', '')1618 ];1619 validationError = new ValidationError(`Gift row 3: Leave credit fee blank.`, 3, 'creditFee');1620 testValidateLedger('Gift credit fee', assetRecords, ledgerRecords, validationError);1621 assetRecords = [1622 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1623 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')1624 ];1625 ledgerRecords = [1626 new LedgerRecord(new Date(2020, 3, 1), 'Gift', 'EUR', 1.2, 1000, '', 'Kraken', '', '', '', '', '', '')1627 ];1628 validationError = new ValidationError(`Gift row 3: Debit asset EUR is fiat. Not supported for gifts given. Use transfer action instead.`, 3, 'debitAsset');1629 testValidateLedger('Gift given debit asset fiat', assetRecords, ledgerRecords, validationError);1630 assetRecords = [1631 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1632 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1633 ];1634 ledgerRecords = [1635 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1636 new LedgerRecord(new Date(2020, 3, 2), 'Gift', 'ADA', '', 1000, '', 'Kraken', '', '', '', '', '', '')1637 ];1638 validationError = new ValidationError(`Gift row 4: For gifts given, debit asset (ADA) to fiat base (USD) exchange rate must be specified.`, 4, 'debitExRate');1639 testValidateLedger('Gift given no debit exrate', assetRecords, ledgerRecords, validationError);1640 assetRecords = [1641 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1642 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1643 ];1644 ledgerRecords = [1645 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1646 new LedgerRecord(new Date(2020, 3, 2), 'Gift', 'ADA', -1.2, 1000, '', 'Kraken', '', '', '', '', '', '')1647 ];1648 validationError = new ValidationError(`Gift row 4: For gifts given, debit exchange rate must be greater than or equal to 0.`, 4, 'debitExRate');1649 testValidateLedger('Gift given negative debit exrate', assetRecords, ledgerRecords, validationError);1650 assetRecords = [1651 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1652 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1653 ];1654 ledgerRecords = [1655 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1656 new LedgerRecord(new Date(2020, 3, 2), 'Gift', 'ADA', 0, 1000, '', 'Kraken', '', '', '', '', '', '')1657 ];1658 validationError = null;1659 testValidateLedger('Gift given zero debit exrate valid', assetRecords, ledgerRecords, validationError);1660 assetRecords = [1661 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1662 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1663 ];1664 ledgerRecords = [1665 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1666 new LedgerRecord(new Date(2020, 3, 2), 'Gift', 'ADA', 1.2, '', '', 'Kraken', '', '', '', '', '', '')1667 ];1668 validationError = new ValidationError(`Gift row 4: For gifts given, debit amount must be specified.`, 4, 'debitAmount');1669 testValidateLedger('Gift given no debit amount', assetRecords, ledgerRecords, validationError);1670 assetRecords = [1671 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1672 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1673 ];1674 ledgerRecords = [1675 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1676 new LedgerRecord(new Date(2020, 3, 2), 'Gift', 'ADA', 1.2, -1000, '', 'Kraken', '', '', '', '', '', '')1677 ];1678 validationError = new ValidationError(`Gift row 4: For gifts given, debit amount must be greater than 0.`, 4, 'debitAmount');1679 testValidateLedger('Gift given negative debit amount', assetRecords, ledgerRecords, validationError);1680 assetRecords = [1681 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1682 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1683 ];1684 ledgerRecords = [1685 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1686 new LedgerRecord(new Date(2020, 3, 2), 'Gift', 'ADA', 1.2, 0, '', 'Kraken', '', '', '', '', '', '')1687 ];1688 validationError = new ValidationError(`Gift row 4: For gifts given, debit amount must be greater than 0.`, 4, 'debitAmount');1689 testValidateLedger('Gift given zero debit amount', assetRecords, ledgerRecords, validationError);1690 assetRecords = [1691 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1692 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1693 ];1694 ledgerRecords = [1695 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1696 new LedgerRecord(new Date(2020, 3, 2), 'Gift', 'ADA', 1.2, 1000, '', 'Kraken', 'ADA', '', '', '', '', '')1697 ];1698 validationError = new ValidationError(`Gift row 4: For gifts given, leave credit asset (ADA) blank.`, 4, 'creditAsset');1699 testValidateLedger('Gift given credit asset', assetRecords, ledgerRecords, validationError);1700 assetRecords = [1701 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1702 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1703 ];1704 ledgerRecords = [1705 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1706 new LedgerRecord(new Date(2020, 3, 2), 'Gift', 'ADA', 1.2, 1000, '', 'Kraken', '', '', 1000, '', '', '')1707 ];1708 validationError = new ValidationError(`Gift row 4: For gifts given, leave credit amount blank.`, 4, 'creditAmount');1709 testValidateLedger('Gift given credit amount', assetRecords, ledgerRecords, validationError);1710 assetRecords = [1711 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1712 new AssetRecord('EUR', 'Fiat', 2, '', '', '', ''),1713 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1714 ];1715 ledgerRecords = [1716 new LedgerRecord(new Date(2020, 3, 1), 'Gift', 'EUR', '', 1000, '', '', 'ADA', '', 1000, '', 'Ledger', '')1717 ];1718 validationError = new ValidationError(`Gift row 3: For gifts received, debit asset must be fiat base (for the inherited cost basis).`, 3, 'debitAsset');1719 testValidateLedger('Gift received debit asset not fiat base', assetRecords, ledgerRecords, validationError);1720 assetRecords = [1721 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1722 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1723 ];1724 ledgerRecords = [1725 new LedgerRecord(new Date(2020, 3, 1), 'Gift', 'USD', '', '', '', '', 'ADA', '', 1000, '', 'Ledger', '')1726 ];1727 validationError = new ValidationError(`Gift row 3: For gifts received, debit amount must be specified (for the inherited cost basis).`, 3, 'debitAmount');1728 testValidateLedger('Gift received no debit amount', assetRecords, ledgerRecords, validationError);1729 assetRecords = [1730 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1731 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1732 ];1733 ledgerRecords = [1734 new LedgerRecord(new Date(2020, 3, 1), 'Gift', 'USD', '', -1200, '', '', 'ADA', '', 1000, '', 'Ledger', '')1735 ];1736 validationError = new ValidationError(`Gift row 3: For gifts received, debit amount must be greater than or equal to 0 (for the inherited cost basis).`, 3, 'debitAmount');1737 testValidateLedger('Gift received negative debit amount', assetRecords, ledgerRecords, validationError);1738 assetRecords = [1739 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1740 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1741 ];1742 ledgerRecords = [1743 new LedgerRecord(new Date(2020, 3, 1), 'Gift', 'USD', '', 0, '', '', 'ADA', '', 1000, '', 'Ledger', '')1744 ];1745 validationError = null;1746 testValidateLedger('Gift received zero debit amount valid', assetRecords, ledgerRecords, validationError);1747 assetRecords = [1748 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1749 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1750 ];1751 ledgerRecords = [1752 new LedgerRecord(new Date(2020, 3, 1), 'Gift', 'USD', '', 1200, '', '', '', '', 1000, '', 'Ledger', '')1753 ];1754 validationError = new ValidationError(`Gift row 3: For gifts received, credit asset must be specified.`, 3, 'creditAsset');1755 testValidateLedger('Gift received no credit asset', assetRecords, ledgerRecords, validationError);1756 assetRecords = [1757 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1758 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')1759 ];1760 ledgerRecords = [1761 new LedgerRecord(new Date(2020, 3, 1), 'Gift', 'USD', '', 1200, '', '', 'EUR', '', 1000, '', 'Ledger', '')1762 ];1763 validationError = new ValidationError(`Gift row 3: Credit asset EUR is fiat. Not supported for gifts received. Use transfer action instead.`, 3, 'creditAsset');1764 testValidateLedger('Gift received credit asset fiat', assetRecords, ledgerRecords, validationError);1765 assetRecords = [1766 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1767 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1768 ];1769 ledgerRecords = [1770 new LedgerRecord(new Date(2020, 3, 1), 'Gift', 'USD', '', 1200, '', '', 'ADA', '', '', '', 'Ledger', '')1771 ];1772 validationError = new ValidationError(`Gift row 3: For gifts received, credit amount must be specified.`, 3, 'creditAmount');1773 testValidateLedger('Gift received no credit amount', assetRecords, ledgerRecords, validationError);1774 assetRecords = [1775 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1776 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1777 ];1778 ledgerRecords = [1779 new LedgerRecord(new Date(2020, 3, 1), 'Gift', 'USD', '', 1200, '', '', 'ADA', '', -1000, '', 'Ledger', '')1780 ];1781 validationError = new ValidationError(`Gift row 3: For gifts received, credit amount must be greater than 0.`, 3, 'creditAmount');1782 testValidateLedger('Gift received negative credit amount', assetRecords, ledgerRecords, validationError);1783 assetRecords = [1784 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1785 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1786 ];1787 ledgerRecords = [1788 new LedgerRecord(new Date(2020, 3, 1), 'Gift', 'USD', '', 1200, '', '', 'ADA', '', 0, '', 'Ledger', '')1789 ];1790 validationError = new ValidationError(`Gift row 3: For gifts received, credit amount must be greater than 0.`, 3, 'creditAmount');1791 testValidateLedger('Gift received zero credit amount', assetRecords, ledgerRecords, validationError);1792}1793function validateLedgerFee() {1794 QUnit.module('Validate Ledger Fee');1795 let assetRecords;1796 let ledgerRecords;1797 let validationError;1798 assetRecords = [1799 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', '')1800 ];1801 ledgerRecords = [1802 new LedgerRecord(new Date(2020, 3, 1), 'Fee', 'USD', '', '', 10, 'Kraken', '', '', '', '', '', '')1803 ];1804 validationError = null;1805 testValidateLedger('Fee fiat base valid', assetRecords, ledgerRecords, validationError);1806 assetRecords = [1807 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1808 new AssetRecord('EUR', 'Fiat', 2, '', '', '', '')1809 ];1810 ledgerRecords = [1811 new LedgerRecord(new Date(2020, 3, 1), 'Fee', 'EUR', '', '', 10, 'Kraken', '', '', '', '', '', '')1812 ];1813 validationError = null;1814 testValidateLedger('Fee fiat valid', assetRecords, ledgerRecords, validationError);1815 assetRecords = [1816 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1817 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1818 ];1819 ledgerRecords = [1820 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1821 new LedgerRecord(new Date(2020, 3, 2), 'Fee', 'ADA', '', '', 10, 'Kraken', '', '', '', '', '', '')1822 ];1823 validationError = null;1824 testValidateLedger('Fee asset valid', assetRecords, ledgerRecords, validationError);1825 assetRecords = [1826 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1827 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1828 ];1829 ledgerRecords = [1830 new LedgerRecord(new Date(2020, 3, 1), 'Fee', '', '', '', 10, 'Kraken', '', '', '', '', '', '')1831 ];1832 validationError = new ValidationError(`Fee row 3: No debit asset specified.`, 3, 'debitAsset');1833 testValidateLedger('Fee no debit asset', assetRecords, ledgerRecords, validationError);1834 assetRecords = [1835 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1836 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1837 ];1838 ledgerRecords = [1839 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1840 new LedgerRecord(new Date(2020, 3, 2), 'Fee', 'ADA', 1.2, '', 10, 'Kraken', '', '', '', '', '', '')1841 ];1842 validationError = new ValidationError(`Fee row 4: Leave debit exchange rate blank.`, 4, 'debitExRate');1843 testValidateLedger('Fee debit exrate', assetRecords, ledgerRecords, validationError);1844 assetRecords = [1845 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1846 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1847 ];1848 ledgerRecords = [1849 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1850 new LedgerRecord(new Date(2020, 3, 2), 'Fee', 'ADA', '', 20, 10, 'Kraken', '', '', '', '', '', '')1851 ];1852 validationError = new ValidationError(`Fee row 4: Leave debit amount blank.`, 4, 'debitAmount');1853 testValidateLedger('Fee debit amount', assetRecords, ledgerRecords, validationError);1854 assetRecords = [1855 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1856 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1857 ];1858 ledgerRecords = [1859 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1860 new LedgerRecord(new Date(2020, 3, 2), 'Fee', 'ADA', '', '', '', 'Kraken', '', '', '', '', '', '')1861 ];1862 validationError = new ValidationError(`Fee row 4: No debit fee specified.`, 4, 'debitFee');1863 testValidateLedger('Fee no debit fee', assetRecords, ledgerRecords, validationError);1864 assetRecords = [1865 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1866 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1867 ];1868 ledgerRecords = [1869 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1870 new LedgerRecord(new Date(2020, 3, 2), 'Fee', 'ADA', '', '', -10, 'Kraken', '', '', '', '', '', '')1871 ];1872 validationError = new ValidationError(`Fee row 4: Debit fee must be greater than 0.`, 4, 'debitFee');1873 testValidateLedger('Fee negative debit fee', assetRecords, ledgerRecords, validationError);1874 assetRecords = [1875 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1876 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1877 ];1878 ledgerRecords = [1879 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1880 new LedgerRecord(new Date(2020, 3, 2), 'Fee', 'ADA', '', '', 0, 'Kraken', '', '', '', '', '', '')1881 ];1882 validationError = new ValidationError(`Fee row 4: Debit fee must be greater than 0.`, 4, 'debitFee');1883 testValidateLedger('Fee zero debit fee', assetRecords, ledgerRecords, validationError);1884 assetRecords = [1885 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1886 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1887 ];1888 ledgerRecords = [1889 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1890 new LedgerRecord(new Date(2020, 3, 2), 'Fee', 'ADA', '', '', 10, '', '', '', '', '', '', '')1891 ];1892 validationError = new ValidationError(`Fee row 4: No debit wallet specified.`, 4, 'debitWalletName');1893 testValidateLedger('Fee no debit wallet', assetRecords, ledgerRecords, validationError);1894 assetRecords = [1895 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1896 new AssetRecord('EUR', 'Fiat', 2, '', '', '', ''),1897 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1898 ];1899 ledgerRecords = [1900 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1901 new LedgerRecord(new Date(2020, 3, 2), 'Fee', 'ADA', '', '', 10, 'Kraken', 'EUR', '', '', '', '', '')1902 ];1903 validationError = new ValidationError(`Fee row 4: Leave credit asset (EUR) blank.`, 4, 'creditAsset');1904 testValidateLedger('Fee credit asset', assetRecords, ledgerRecords, validationError);1905 assetRecords = [1906 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1907 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1908 ];1909 ledgerRecords = [1910 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1911 new LedgerRecord(new Date(2020, 3, 2), 'Fee', 'ADA', '', '', 10, 'Kraken', '', 1.2, '', '', '', '')1912 ];1913 validationError = new ValidationError(`Fee row 4: Leave credit exchange rate blank.`, 4, 'creditExRate');1914 testValidateLedger('Fee credit exrate', assetRecords, ledgerRecords, validationError);1915 assetRecords = [1916 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1917 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1918 ];1919 ledgerRecords = [1920 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1921 new LedgerRecord(new Date(2020, 3, 2), 'Fee', 'ADA', '', '', 10, 'Kraken', '', '', 10, '', '', '')1922 ];1923 validationError = new ValidationError(`Fee row 4: Leave credit amount blank.`, 4, 'creditAmount');1924 testValidateLedger('Fee credit amount', assetRecords, ledgerRecords, validationError);1925 assetRecords = [1926 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1927 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1928 ];1929 ledgerRecords = [1930 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1931 new LedgerRecord(new Date(2020, 3, 2), 'Fee', 'ADA', '', '', 10, 'Kraken', '', '', '', 10, '', '')1932 ];1933 validationError = new ValidationError(`Fee row 4: Leave credit fee blank.`, 4, 'creditFee');1934 testValidateLedger('Fee credit fee', assetRecords, ledgerRecords, validationError);1935 assetRecords = [1936 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1937 new AssetRecord('ADA', 'Crypto', 6, '', '', '', '')1938 ];1939 ledgerRecords = [1940 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 1200, '', 'Kraken', 'ADA', '', 1000, '', '', ''),1941 new LedgerRecord(new Date(2020, 3, 2), 'Fee', 'ADA', '', '', 10, 'Kraken', '', '', '', '', 'IB', '')1942 ];1943 validationError = new ValidationError(`Fee row 4: Leave credit wallet (IB) blank.`, 4, 'creditWalletName');1944 testValidateLedger('Fee credit wallet', assetRecords, ledgerRecords, validationError);1945}1946function validateLedgerSplit() {1947 QUnit.module('Validate Ledger Split');1948 let assetRecords;1949 let ledgerRecords;1950 let validationError;1951 assetRecords = [1952 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1953 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')1954 ];1955 ledgerRecords = [1956 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),1957 new LedgerRecord(new Date(2020, 3, 2), 'Split', 'LMN', '', 750, '', '', '', '', '', '', '', '')1958 ];1959 validationError = null;1960 testValidateLedger('Split reverse split no wallet valid', assetRecords, ledgerRecords, validationError);1961 assetRecords = [1962 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1963 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')1964 ];1965 ledgerRecords = [1966 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),1967 new LedgerRecord(new Date(2020, 3, 2), 'Split', 'LMN', '', 750, '', 'IB', '', '', '', '', '', '')1968 ];1969 validationError = null;1970 testValidateLedger('Split reverse split with wallet valid', assetRecords, ledgerRecords, validationError);1971 assetRecords = [1972 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1973 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')1974 ];1975 ledgerRecords = [1976 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),1977 new LedgerRecord(new Date(2020, 3, 2), 'Split', '', '', '', '', '', 'LMN', '', 3000, '', '', '')1978 ];1979 validationError = null;1980 testValidateLedger('Split forward split no wallet valid', assetRecords, ledgerRecords, validationError);1981 assetRecords = [1982 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1983 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')1984 ];1985 ledgerRecords = [1986 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),1987 new LedgerRecord(new Date(2020, 3, 2), 'Split', '', '', '', '', '', 'LMN', '', 3000, '', 'IB', '')1988 ];1989 validationError = null;1990 testValidateLedger('Split forward split with wallet valid', assetRecords, ledgerRecords, validationError);1991 assetRecords = [1992 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),1993 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')1994 ];1995 ledgerRecords = [1996 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),1997 new LedgerRecord(new Date(2020, 3, 2), 'Split', 'LMN', '', 750, '', '', 'LMN', '', 3000, '', '', '')1998 ];1999 validationError = new ValidationError(`Split row 4: Either enter debit asset and debit amount for reverse splits (decrease amount held) or credit asset and credit amount for foward splits (increase amount held).`, 4, 'debitAsset');2000 testValidateLedger('Split debit asset, debit amount, credit asset, credit amount ââââ debit asset column', assetRecords, ledgerRecords, validationError);2001 assetRecords = [2002 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),2003 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')2004 ];2005 ledgerRecords = [2006 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),2007 new LedgerRecord(new Date(2020, 3, 2), 'Split', 'LMN', '', '', '', '', 'LMN', '', 3000, '', '', '')2008 ];2009 validationError = new ValidationError(`Split row 4: Either enter debit asset and debit amount for reverse splits (decrease amount held) or credit asset and credit amount for foward splits (increase amount held).`, 4, 'debitAsset');2010 testValidateLedger('Split debit asset, debit amount, credit asset, credit amount ââââ debit asset column', assetRecords, ledgerRecords, validationError);2011 assetRecords = [2012 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),2013 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')2014 ];2015 ledgerRecords = [2016 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),2017 new LedgerRecord(new Date(2020, 3, 2), 'Split', 'LMN', '', '', '', '', 'LMN', '', '', '', '', '')2018 ];2019 validationError = new ValidationError(`Split row 4: Either enter debit asset and debit amount for reverse splits (decrease amount held) or credit asset and credit amount for foward splits (increase amount held).`, 4, 'debitAsset');2020 testValidateLedger('Split debit asset, debit amount, credit asset, credit amount ââââ debit asset column', assetRecords, ledgerRecords, validationError);2021 assetRecords = [2022 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),2023 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')2024 ];2025 ledgerRecords = [2026 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),2027 new LedgerRecord(new Date(2020, 3, 2), 'Split', 'LMN', '', '', '', '', '', '', 3000, '', '', '')2028 ];2029 validationError = new ValidationError(`Split row 4: Either enter debit asset and debit amount for reverse splits (decrease amount held) or credit asset and credit amount for foward splits (increase amount held).`, 4, 'debitAsset');2030 testValidateLedger('Split debit asset, debit amount, credit asset, credit amount ââââ debit asset column', assetRecords, ledgerRecords, validationError);2031 assetRecords = [2032 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),2033 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')2034 ];2035 ledgerRecords = [2036 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),2037 new LedgerRecord(new Date(2020, 3, 2), 'Split', '', '', '750', '', '', '', '', '', '', '', '')2038 ];2039 validationError = new ValidationError(`Split row 4: Either enter debit asset and debit amount for reverse splits (decrease amount held) or credit asset and credit amount for foward splits (increase amount held).`, 4, 'debitAsset');2040 testValidateLedger('Split debit asset, debit amount, credit asset, credit amount ââââ debit asset column', assetRecords, ledgerRecords, validationError);2041 assetRecords = [2042 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),2043 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')2044 ];2045 ledgerRecords = [2046 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),2047 new LedgerRecord(new Date(2020, 3, 2), 'Split', '', '', '', '', '', '', '', '', '', '', '')2048 ];2049 validationError = new ValidationError(`Split row 4: Either enter debit asset and debit amount for reverse splits (decrease amount held) or credit asset and credit amount for foward splits (increase amount held).`, 4, 'debitAsset');2050 testValidateLedger('Split debit asset, debit amount, credit asset, credit amount ââââ debit asset column', assetRecords, ledgerRecords, validationError);2051 assetRecords = [2052 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),2053 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')2054 ];2055 ledgerRecords = [2056 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),2057 new LedgerRecord(new Date(2020, 3, 2), 'Split', 'LMN', '', '', '', '', '', '', '', '', '', '')2058 ];2059 validationError = new ValidationError(`Split row 4: Either enter debit asset and debit amount for reverse splits (decrease amount held) or credit asset and credit amount for foward splits (increase amount held).`, 4, 'debitAmount');2060 testValidateLedger('Split debit asset, debit amount, credit asset, credit amount ââââ debit amount column', assetRecords, ledgerRecords, validationError);2061 assetRecords = [2062 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),2063 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')2064 ];2065 ledgerRecords = [2066 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),2067 new LedgerRecord(new Date(2020, 3, 2), 'Split', '', '', 750, '', '', 'LMN', '', 3000, '', '', '')2068 ];2069 validationError = new ValidationError(`Split row 4: Either enter debit asset and debit amount for reverse splits (decrease amount held) or credit asset and credit amount for foward splits (increase amount held).`, 4, 'debitAmount');2070 testValidateLedger('Split debit asset, debit amount, credit asset, credit amount ââââ debit amount column', assetRecords, ledgerRecords, validationError);2071 assetRecords = [2072 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),2073 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')2074 ];2075 ledgerRecords = [2076 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),2077 new LedgerRecord(new Date(2020, 3, 2), 'Split', '', '', 750, '', '', 'LMN', '', '', '', '', '')2078 ];2079 validationError = new ValidationError(`Split row 4: Either enter debit asset and debit amount for reverse splits (decrease amount held) or credit asset and credit amount for foward splits (increase amount held).`, 4, 'debitAmount');2080 testValidateLedger('Split debit asset, debit amount, credit asset, credit amount ââââ debit amount column', assetRecords, ledgerRecords, validationError);2081 assetRecords = [2082 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),2083 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')2084 ];2085 ledgerRecords = [2086 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),2087 new LedgerRecord(new Date(2020, 3, 2), 'Split', '', '', 750, '', '', '', '', 3000, '', '', '')2088 ];2089 validationError = new ValidationError(`Split row 4: Either enter debit asset and debit amount for reverse splits (decrease amount held) or credit asset and credit amount for foward splits (increase amount held).`, 4, 'debitAmount');2090 testValidateLedger('Split debit asset, debit amount, credit asset, credit amount ââââ debit amount column', assetRecords, ledgerRecords, validationError);2091 assetRecords = [2092 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),2093 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')2094 ];2095 ledgerRecords = [2096 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),2097 new LedgerRecord(new Date(2020, 3, 2), 'Split', 'LMN', '', 750, '', '', 'LMN', '', '', '', '', '')2098 ];2099 validationError = new ValidationError(`Split row 4: Either enter debit asset and debit amount for reverse splits (decrease amount held) or credit asset and credit amount for foward splits (increase amount held).`, 4, 'creditAsset');2100 testValidateLedger('Split debit asset, debit amount, credit asset, credit amount ââââ credit asset column', assetRecords, ledgerRecords, validationError);2101 assetRecords = [2102 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),2103 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')2104 ];2105 ledgerRecords = [2106 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),2107 new LedgerRecord(new Date(2020, 3, 2), 'Split', '', '', '', '', '', '', '', 3000, '', '', '')2108 ];2109 validationError = new ValidationError(`Split row 4: Either enter debit asset and debit amount for reverse splits (decrease amount held) or credit asset and credit amount for foward splits (increase amount held).`, 4, 'creditAsset');2110 testValidateLedger('Split debit asset, debit amount, credit asset, credit amount ââââ credit asset column', assetRecords, ledgerRecords, validationError);2111 assetRecords = [2112 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),2113 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')2114 ];2115 ledgerRecords = [2116 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),2117 new LedgerRecord(new Date(2020, 3, 2), 'Split', 'LMN', '', 750, '', '', '', '', 3000, '', '', '')2118 ];2119 validationError = new ValidationError(`Split row 4: Either enter debit asset and debit amount for reverse splits (decrease amount held) or credit asset and credit amount for foward splits (increase amount held).`, 4, 'creditAmount');2120 testValidateLedger('Split debit asset, debit amount, credit asset, credit amount ââââ credit amount column', assetRecords, ledgerRecords, validationError);2121 assetRecords = [2122 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),2123 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')2124 ];2125 ledgerRecords = [2126 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),2127 new LedgerRecord(new Date(2020, 3, 2), 'Split', '', '', '', '', '', 'LMN', '', '', '', '', '')2128 ];2129 validationError = new ValidationError(`Split row 4: Either enter debit asset and debit amount for reverse splits (decrease amount held) or credit asset and credit amount for foward splits (increase amount held).`, 4, 'creditAmount');2130 testValidateLedger('Split debit asset, debit amount, credit asset, credit amount ââââ credit amount column', assetRecords, ledgerRecords, validationError);2131 assetRecords = [2132 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),2133 new AssetRecord('EUR', 'Fiat', 2, '', '', '', ''),2134 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')2135 ];2136 ledgerRecords = [2137 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),2138 new LedgerRecord(new Date(2020, 3, 2), 'Split', 'EUR', '', 750, '', '', '', '', '', '', '', '')2139 ];2140 validationError = new ValidationError(`Split row 4: Debit asset (EUR) is fiat, not supported.`, 4, 'debitAsset');2141 testValidateLedger('Split debit asset fiat', assetRecords, ledgerRecords, validationError);2142 assetRecords = [2143 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),2144 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')2145 ];2146 ledgerRecords = [2147 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),2148 new LedgerRecord(new Date(2020, 3, 2), 'Split', 'LMN', 2, 750, '', '', '', '', '', '', '', '')2149 ];2150 validationError = new ValidationError(`Split row 4: Leave debit exchange rate blank.`, 4, 'debitExRate');2151 testValidateLedger('Split debit exrate', assetRecords, ledgerRecords, validationError);2152 assetRecords = [2153 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),2154 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')2155 ];2156 ledgerRecords = [2157 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),2158 new LedgerRecord(new Date(2020, 3, 2), 'Split', 'LMN', '', -750, '', '', '', '', '', '', '', '')2159 ];2160 validationError = new ValidationError(`Split row 4: Debit amount must be greater than 0.`, 4, 'debitAmount');2161 testValidateLedger('Split negative debit amount', assetRecords, ledgerRecords, validationError);2162 assetRecords = [2163 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),2164 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')2165 ];2166 ledgerRecords = [2167 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),2168 new LedgerRecord(new Date(2020, 3, 2), 'Split', 'LMN', '', 0, '', '', '', '', '', '', '', '')2169 ];2170 validationError = new ValidationError(`Split row 4: Debit amount must be greater than 0.`, 4, 'debitAmount');2171 testValidateLedger('Split zero debit amount', assetRecords, ledgerRecords, validationError);2172 assetRecords = [2173 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),2174 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')2175 ];2176 ledgerRecords = [2177 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),2178 new LedgerRecord(new Date(2020, 3, 2), 'Split', 'LMN', '', 750, 10, '', '', '', '', '', '', '')2179 ];2180 validationError = new ValidationError(`Split row 4: Leave debit fee blank.`, 4, 'debitFee');2181 testValidateLedger('Split debit fee', assetRecords, ledgerRecords, validationError);2182 assetRecords = [2183 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),2184 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')2185 ];2186 ledgerRecords = [2187 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),2188 new LedgerRecord(new Date(2020, 3, 2), 'Split', '', '', '', '', 'IB', 'LMN', '', 3000, '', '', '')2189 ];2190 validationError = new ValidationError(`Split row 4: For foward splits (increase amount held) leave debit wallet (IB) blank.`, 4, 'debitWalletName');2191 testValidateLedger('Split foward split debit wallet', assetRecords, ledgerRecords, validationError);2192 assetRecords = [2193 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),2194 new AssetRecord('EUR', 'Fiat', 2, '', '', '', ''),2195 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')2196 ];2197 ledgerRecords = [2198 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),2199 new LedgerRecord(new Date(2020, 3, 2), 'Split', '', '', '', '', '', 'EUR', '', 3000, '', '', '')2200 ];2201 validationError = new ValidationError(`Split row 4: Credit asset (EUR) is fiat, not supported.`, 4, 'creditAsset');2202 testValidateLedger('Split credit asset fiat', assetRecords, ledgerRecords, validationError);2203 assetRecords = [2204 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),2205 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')2206 ];2207 ledgerRecords = [2208 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),2209 new LedgerRecord(new Date(2020, 3, 2), 'Split', '', '', '', '', '', 'LMN', 2, 3000, '', '', '')2210 ];2211 validationError = new ValidationError(`Split row 4: Leave credit exchange rate blank.`, 4, 'creditExRate');2212 testValidateLedger('Split credit exrate', assetRecords, ledgerRecords, validationError);2213 assetRecords = [2214 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),2215 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')2216 ];2217 ledgerRecords = [2218 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),2219 new LedgerRecord(new Date(2020, 3, 2), 'Split', '', '', '', '', '', 'LMN', '', -3000, '', '', '')2220 ];2221 validationError = new ValidationError(`Split row 4: Credit amount must be greater than 0.`, 4, 'creditAmount');2222 testValidateLedger('Split negative credit amount', assetRecords, ledgerRecords, validationError);2223 assetRecords = [2224 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),2225 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')2226 ];2227 ledgerRecords = [2228 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),2229 new LedgerRecord(new Date(2020, 3, 2), 'Split', '', '', '', '', '', 'LMN', '', 0, '', '', '')2230 ];2231 validationError = new ValidationError(`Split row 4: Credit amount must be greater than 0.`, 4, 'creditAmount');2232 testValidateLedger('Split zero credit amount', assetRecords, ledgerRecords, validationError);2233 assetRecords = [2234 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),2235 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')2236 ];2237 ledgerRecords = [2238 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),2239 new LedgerRecord(new Date(2020, 3, 2), 'Split', '', '', '', '', '', 'LMN', '', 3000, 10, '', '')2240 ];2241 validationError = new ValidationError(`Split row 4: Leave credit fee blank.`, 4, 'creditFee');2242 testValidateLedger('Split credit fee', assetRecords, ledgerRecords, validationError);2243 assetRecords = [2244 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),2245 new AssetRecord('LMN', 'Stock', 0, '', '', '', '')2246 ];2247 ledgerRecords = [2248 new LedgerRecord(new Date(2020, 3, 1), 'Trade', 'USD', '', 2000, '', 'IB', 'LMN', '', 1000, 0, '', ''),2249 new LedgerRecord(new Date(2020, 3, 2), 'Split', 'LMN', '', 750, '', '', '', '', '', '', 'IB', '')2250 ];2251 validationError = new ValidationError(`Split row 4: For reverse splits (decrease amount held) leave credit wallet (IB) blank.`, 4, 'creditWalletName');2252 testValidateLedger('Split reverse split credit wallet', assetRecords, ledgerRecords, validationError);...
types_validator.js
Source:types_validator.js
...5// ValidatePosition validates the needed type constraints6// from v and cast it to Position.7export function ValidatePosition(v) {8 if (typeof v.x !== "number") {9 throw new ValidationError("missing v.x");10 }11 if (typeof v.y !== "number") {12 throw new ValidationError("missing v.y");13 }14 return v;15}16// ValidateVelocity validates the needed type constraints17// from v and cast it to Velocity.18export function ValidateVelocity(v) {19 if (typeof v.x !== "number") {20 throw new ValidationError("missing v.x");21 }22 if (typeof v.y !== "number") {23 throw new ValidationError("missing v.y");24 }25 return v;26}27// ValidateScore validates the needed type constraints28// from v and cast it to Score.29export function ValidateScore(v) {30 if (typeof v.username !== "string") {31 throw new ValidationError("missing v.username");32 }33 if (v.time === undefined) {34 throw new ValidationError("missing v.time");35 }36 return v;37}38// ValidateEvent validates the needed type constraints39// from v and cast it to Event.40export function ValidateEvent(v) {41 switch (v.type) {42 case "HELLO": {43 ValidateHelloEvent(v);44 break;45 }46 case "WARNING": {47 ValidateWarningEvent(v);48 break;49 }50 case "LEVEL_FINISHED": {51 ValidateLevelFinishedEvent(v);52 break;53 }54 case "ENTITY_MOVE": {55 ValidateEntityMoveEvent(v);56 break;57 }58 case undefined: {59 throw new ValidationError("missing v.type");60 }61 default: {62 throw new ValidationError("unknown v.type given");63 }64 }65 return v;66}67// ValidateHelloEvent validates the needed type constraints68// from v and cast it to HelloEvent.69export function ValidateHelloEvent(v) {70 if (v.type !== "HELLO") {71 throw new ValidationError("missing v.type");72 }73 if (v.d === undefined) {74 throw new ValidationError("missing v.d");75 }76 if (typeof v.d.username !== "string") {77 throw new ValidationError("missing v.d.username");78 }79 if (typeof v.d.nLevels !== "number") {80 throw new ValidationError("missing v.d.nLevels");81 }82 if (typeof v.d.completedLevels !== "object") {83 throw new ValidationError("missing v.d.completedLevels");84 }85 return v;86}87// ValidateWarningEvent validates the needed type constraints88// from v and cast it to WarningEvent.89export function ValidateWarningEvent(v) {90 if (v.type !== "WARNING") {91 throw new ValidationError("missing v.type");92 }93 if (v.d === undefined) {94 throw new ValidationError("missing v.d");95 }96 if (typeof v.d.message !== "string") {97 throw new ValidationError("missing v.d.message");98 }99 return v;100}101// ValidateLevelJoinedEvent validates the needed type constraints102// from v and cast it to LevelJoinedEvent.103export function ValidateLevelJoinedEvent(v) {104 if (v.type !== "LEVEL_JOINED") {105 throw new ValidationError("missing v.type");106 }107 if (v.d === undefined) {108 throw new ValidationError("missing v.d");109 }110 if (typeof v.d.level !== "number") {111 throw new ValidationError("missing v.d.level");112 }113 return v;114}115// ValidateLevelFinishedEvent validates the needed type constraints116// from v and cast it to LevelFinishedEvent.117export function ValidateLevelFinishedEvent(v) {118 if (v.type !== "LEVEL_FINISHED") {119 throw new ValidationError("missing v.type");120 }121 if (v.d === undefined) {122 throw new ValidationError("missing v.d");123 }124 if (typeof v.d.level !== "number") {125 throw new ValidationError("missing v.d.level");126 }127 if (typeof v.d.won !== "boolean") {128 throw new ValidationError("missing v.d.won");129 }130 if (v.d.time === undefined) {131 throw new ValidationError("missing v.d.time");132 }133 return v;134}135// ValidateEntityPositionData validates the needed type constraints136// from v and cast it to EntityPositionData.137export function ValidateEntityPositionData(v) {138 if (v.initial === undefined) {139 throw new ValidationError("missing v.initial");140 }141 ValidatePosition(v.initial);142 if (v.position === undefined) {143 throw new ValidationError("missing v.position");144 }145 ValidatePosition(v.position);146 return v;147}148// ValidateEntityMoveEvent validates the needed type constraints149// from v and cast it to EntityMoveEvent.150export function ValidateEntityMoveEvent(v) {151 if (v.type !== "ENTITY_MOVE") {152 throw new ValidationError("missing v.type");153 }154 if (v.d === undefined) {155 throw new ValidationError("missing v.d");156 }157 if (typeof v.d.level !== "number") {158 throw new ValidationError("missing v.d.level");159 }160 if (typeof v.d.entities !== "object") {161 throw new ValidationError("missing v.d.entities");162 }163 return v;164}165// ValidateCommand validates the needed type constraints166// from v and cast it to Command.167export function ValidateCommand(v) {168 switch (v.type) {169 case "JOIN": {170 ValidateJoinCommand(v);171 break;172 }173 case "MOVE": {174 ValidateMoveCommand(v);175 break;176 }177 case undefined: {178 throw new ValidationError("missing v.type");179 }180 default: {181 throw new ValidationError("unknown v.type given");182 }183 }184 return v;185}186// ValidateJoinCommand validates the needed type constraints187// from v and cast it to JoinCommand.188export function ValidateJoinCommand(v) {189 if (v.type !== "JOIN") {190 throw new ValidationError("missing v.type");191 }192 if (v.d === undefined) {193 throw new ValidationError("missing v.d");194 }195 if (typeof v.d.level !== "number") {196 throw new ValidationError("missing v.d.level");197 }198 return v;199}200// ValidateMoveCommand validates the needed type constraints201// from v and cast it to MoveCommand.202export function ValidateMoveCommand(v) {203 if (v.type !== "MOVE") {204 throw new ValidationError("missing v.type");205 }206 if (v.d === undefined) {207 throw new ValidationError("missing v.d");208 }209 if (v.d.position === undefined) {210 throw new ValidationError("missing v.d.position");211 }212 ValidatePosition(v.d.position);213 return v;...
ValidateAssets.gs
Source:ValidateAssets.gs
...23 let validationError;24 assetRecords = [25 new AssetRecord('USD', 'Fiat', 2, 1, '', '', '')26 ];27 validationError = new ValidationError(`Fiat Base has not been declared in the Assets sheet. One asset must have asset type of 'Fiat Base'.`, 2, 'assetType');28 testValidateAssets('No fiat base', assetRecords, validationError);29 assetRecords = [30 new AssetRecord('', 'Fiat Base', 2, 1, '', '', '')31 ];32 validationError = new ValidationError(`Assets row 2: Asset is missing.`, 2, 'ticker');33 testValidateAssets('No asset ticker', assetRecords, validationError);34 assetRecords = [35 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),36 new AssetRecord('USD', 'Fiat', 2, 1, '', '', '')37 ];38 validationError = new ValidationError(`Assets row 3: Duplicate entry for (USD). An asset can only be declared once`, 3, 'ticker');39 testValidateAssets('Duplicate asset', assetRecords, validationError);40 assetRecords = [41 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),42 new AssetRecord('#', 'Stock', 0, '', '', '', '')43 ];44 validationError = new ValidationError(`Assets row 3: Asset (#) format is invalid.\nInput must be 1-10 characters [A-Za-z0-9_$@].\nOptional prefix of 1-15 characters [A-Za-z0-9_] and colon [:].`, 3, 'ticker');45 testValidateAssets('Invalid asset format', assetRecords, validationError);46 assetRecords = [47 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),48 new AssetRecord('LMN', '', 0, '', '', '', '')49 ];50 validationError = new ValidationError(`Assets row 3: Asset type is missing.`, 3, 'assetType');51 testValidateAssets('No asset type', assetRecords, validationError);52 assetRecords = [53 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),54 new AssetRecord('LMN', '#', 0, '', '', '', '')55 ];56 validationError = new ValidationError(`Assets row 3: Asset type (#) format is invalid.\nInput must be between 1 and 20 characters [A-Za-z0-9_-].\nSpaces between characters allowed.`, 3, 'assetType');57 testValidateAssets('Invalid asset type format', assetRecords, validationError);58 assetRecords = [59 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),60 new AssetRecord('EUR', 'Fiat Base', 2, 1, '', '', '')61 ];62 validationError = new ValidationError(`Assets row 3: Fiat base has already been declared (USD). Only one asset can be fiat base.`, 3, 'assetType');63 testValidateAssets('Duplicate fiat base', assetRecords, validationError);64 assetRecords = [65 new AssetRecord('USD', 'Fiat Base', '', 1, '', '', '')66 ];67 validationError = new ValidationError(`Assets row 2: Decimal places is missing.`, 2, 'decimalPlaces');68 testValidateAssets('No decimal places', assetRecords, validationError);69 assetRecords = [70 new AssetRecord('USD', 'Fiat Base', 9, 1, '', '', '')71 ];72 validationError = new ValidationError(`Assets row 2: Decimal places is not valid (integer between 0 and 8).`, 2, 'decimalPlaces');73 testValidateAssets('Invalid decimal places', assetRecords, validationError);74 assetRecords = [75 new AssetRecord('USD', 'Fiat Base', 2, 2, '', '', '')76 ];77 validationError = new ValidationError(`Assets row 2: Fiat base current price must be 1.`, 2, 'currentPrice');78 testValidateAssets('Fiat base current price not equal to 1', assetRecords, validationError);79 assetRecords = [80 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),81 new AssetRecord('EUR', 'Fiat', 2, 'abc', '', '', '')82 ];83 validationError = new ValidationError(`Assets row 3: Current price (abc) is not valid (number or blank).`, 3, 'currentPrice');84 testValidateAssets('Invalid current price', assetRecords, validationError);85 assetRecords = [86 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),87 new AssetRecord('EUR', 'Fiat', 2, -1, '', '', '')88 ];89 validationError = new ValidationError(`Assets row 3: Current price must be greater than or equal to 0 (or blank).`, 3, 'currentPrice');90 testValidateAssets('Negative current price', assetRecords, validationError);91 assetRecords = [92 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),93 new AssetRecord('DOGE', 'Crypto', 8, 0, '', '', '')94 ];95 validationError = null;96 testValidateAssets('Zero current price valid', assetRecords, validationError);97 assetRecords = [98 new AssetRecord('USD', 'Fiat Base', 2, 1, '', '', ''),99 new AssetRecord('EUR', 'Fiat', 2, '', '', 'InvalidAPI', '')100 ];101 validationError = new ValidationError(`Assets row 3: API (InvalidAPI) is not valid (CoinMarketCap, CryptoCompare) or blank.`, 3, 'apiName');102 testValidateAssets('Invalid API', assetRecords, validationError);...
ValidationError.spec.ts
Source:ValidationError.spec.ts
...3describe("ValidationError", () => {4 it("ValidationError object can be created", () => {5 const TEST_ERROR_CODE: string = "test";6 const TEST_ERROR_MESSAGE: string = "This is a test error";7 const err: ValidationError = new ValidationError(TEST_ERROR_CODE, TEST_ERROR_MESSAGE);8 expect(err instanceof ValidationError).toBe(true);9 expect(err instanceof AuthError).toBe(true);10 expect(err instanceof Error).toBe(true);11 expect(err.errorCode).toBe(TEST_ERROR_CODE);12 expect(err.errorMessage).toBe(TEST_ERROR_MESSAGE);13 expect(err.message).toBe(`${TEST_ERROR_CODE}: ${TEST_ERROR_MESSAGE}`);14 expect(err.name).toBe("ValidationError");15 expect(err.stack?.includes("ValidationError.spec.ts")).toBe(true);16 });17 18 it("createInvalidNonceError creates a ValidationError object", () => {19 const err: ValidationError = ValidationError.createInvalidNonceError();20 expect(err instanceof ValidationError).toBe(true);21 expect(err instanceof AuthError).toBe(true);...
Using AI Code Generation
1var stf = require('devicefarmer-stf');2var util = require('util');3var ValidationError = stf.ValidationError;4var validationError = new ValidationError('some error message');5console.log(util.inspect(validationError));6var stf = require('devicefarmer-stf-client');7var util = require('util');8var ValidationError = stf.ValidationError;9var validationError = new ValidationError('some error message');10console.log(util.inspect(validationError));11{ ValidationError: some error message12 at new ValidationError (/Users/xxxxx/Desktop/devicefarmer-stf/node_modules/devicefarmer-stf-client/lib/util/errors.js:18:15)13 at Object.<anonymous> (/Users/xxxxx/Desktop/devicefarmer-stf/test.js:6:26)14 at Module._compile (module.js:409:26)15 at Object.Module._extensions..js (module.js:416:10)16 at Module.load (module.js:343:32)17 at Function.Module._load (module.js:300:12)18 at Function.Module.runMain (module.js:441:10)19 at startup (node.js:139:18)20 message: 'some error message' }
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!