Best JavaScript code snippet using stryker-parent
importmulti.py
Source:importmulti.py
...16 self.log.info("Mining blocks...")17 self.nodes[0].generate(1)18 self.nodes[1].generate(1)19 timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']20 node0_address1 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())21 #Check only one address22 assert_equal(node0_address1['ismine'], True)23 #Node 1 sync test24 assert_equal(self.nodes[1].getblockcount(),1)25 #Address Test - before import26 address_info = self.nodes[1].validateaddress(node0_address1['address'])27 assert_equal(address_info['iswatchonly'], False)28 assert_equal(address_info['ismine'], False)29 # RPC importmulti -----------------------------------------------30 # Californiacoin Address31 self.log.info("Should import an address")32 address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())33 result = self.nodes[1].importmulti([{34 "scriptPubKey": {35 "address": address['address']36 },37 "timestamp": "now",38 }])39 assert_equal(result[0]['success'], True)40 address_assert = self.nodes[1].validateaddress(address['address'])41 assert_equal(address_assert['iswatchonly'], True)42 assert_equal(address_assert['ismine'], False)43 assert_equal(address_assert['timestamp'], timestamp)44 watchonly_address = address['address']45 watchonly_timestamp = timestamp46 self.log.info("Should not import an invalid address")47 result = self.nodes[1].importmulti([{48 "scriptPubKey": {49 "address": "not valid address",50 },51 "timestamp": "now",52 }])53 assert_equal(result[0]['success'], False)54 assert_equal(result[0]['error']['code'], -5)55 assert_equal(result[0]['error']['message'], 'Invalid address')56 # ScriptPubKey + internal57 self.log.info("Should import a scriptPubKey with internal flag")58 address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())59 result = self.nodes[1].importmulti([{60 "scriptPubKey": address['scriptPubKey'],61 "timestamp": "now",62 "internal": True63 }])64 assert_equal(result[0]['success'], True)65 address_assert = self.nodes[1].validateaddress(address['address'])66 assert_equal(address_assert['iswatchonly'], True)67 assert_equal(address_assert['ismine'], False)68 assert_equal(address_assert['timestamp'], timestamp)69 # ScriptPubKey + !internal70 self.log.info("Should not import a scriptPubKey without internal flag")71 address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())72 result = self.nodes[1].importmulti([{73 "scriptPubKey": address['scriptPubKey'],74 "timestamp": "now",75 }])76 assert_equal(result[0]['success'], False)77 assert_equal(result[0]['error']['code'], -8)78 assert_equal(result[0]['error']['message'], 'Internal must be set for hex scriptPubKey')79 address_assert = self.nodes[1].validateaddress(address['address'])80 assert_equal(address_assert['iswatchonly'], False)81 assert_equal(address_assert['ismine'], False)82 assert_equal('timestamp' in address_assert, False)83 # Address + Public key + !Internal84 self.log.info("Should import an address with public key")85 address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())86 result = self.nodes[1].importmulti([{87 "scriptPubKey": {88 "address": address['address']89 },90 "timestamp": "now",91 "pubkeys": [ address['pubkey'] ]92 }])93 assert_equal(result[0]['success'], True)94 address_assert = self.nodes[1].validateaddress(address['address'])95 assert_equal(address_assert['iswatchonly'], True)96 assert_equal(address_assert['ismine'], False)97 assert_equal(address_assert['timestamp'], timestamp)98 # ScriptPubKey + Public key + internal99 self.log.info("Should import a scriptPubKey with internal and with public key")100 address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())101 request = [{102 "scriptPubKey": address['scriptPubKey'],103 "timestamp": "now",104 "pubkeys": [ address['pubkey'] ],105 "internal": True106 }]107 result = self.nodes[1].importmulti(request)108 assert_equal(result[0]['success'], True)109 address_assert = self.nodes[1].validateaddress(address['address'])110 assert_equal(address_assert['iswatchonly'], True)111 assert_equal(address_assert['ismine'], False)112 assert_equal(address_assert['timestamp'], timestamp)113 # ScriptPubKey + Public key + !internal114 self.log.info("Should not import a scriptPubKey without internal and with public key")115 address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())116 request = [{117 "scriptPubKey": address['scriptPubKey'],118 "timestamp": "now",119 "pubkeys": [ address['pubkey'] ]120 }]121 result = self.nodes[1].importmulti(request)122 assert_equal(result[0]['success'], False)123 assert_equal(result[0]['error']['code'], -8)124 assert_equal(result[0]['error']['message'], 'Internal must be set for hex scriptPubKey')125 address_assert = self.nodes[1].validateaddress(address['address'])126 assert_equal(address_assert['iswatchonly'], False)127 assert_equal(address_assert['ismine'], False)128 assert_equal('timestamp' in address_assert, False)129 # Address + Private key + !watchonly130 self.log.info("Should import an address with private key")131 address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())132 result = self.nodes[1].importmulti([{133 "scriptPubKey": {134 "address": address['address']135 },136 "timestamp": "now",137 "keys": [ self.nodes[0].dumpprivkey(address['address']) ]138 }])139 assert_equal(result[0]['success'], True)140 address_assert = self.nodes[1].validateaddress(address['address'])141 assert_equal(address_assert['iswatchonly'], False)142 assert_equal(address_assert['ismine'], True)143 assert_equal(address_assert['timestamp'], timestamp)144 self.log.info("Should not import an address with private key if is already imported")145 result = self.nodes[1].importmulti([{146 "scriptPubKey": {147 "address": address['address']148 },149 "timestamp": "now",150 "keys": [ self.nodes[0].dumpprivkey(address['address']) ]151 }])152 assert_equal(result[0]['success'], False)153 assert_equal(result[0]['error']['code'], -4)154 assert_equal(result[0]['error']['message'], 'The wallet already contains the private key for this address or script')155 # Address + Private key + watchonly156 self.log.info("Should not import an address with private key and with watchonly")157 address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())158 result = self.nodes[1].importmulti([{159 "scriptPubKey": {160 "address": address['address']161 },162 "timestamp": "now",163 "keys": [ self.nodes[0].dumpprivkey(address['address']) ],164 "watchonly": True165 }])166 assert_equal(result[0]['success'], False)167 assert_equal(result[0]['error']['code'], -8)168 assert_equal(result[0]['error']['message'], 'Incompatibility found between watchonly and keys')169 address_assert = self.nodes[1].validateaddress(address['address'])170 assert_equal(address_assert['iswatchonly'], False)171 assert_equal(address_assert['ismine'], False)172 assert_equal('timestamp' in address_assert, False)173 # ScriptPubKey + Private key + internal174 self.log.info("Should import a scriptPubKey with internal and with private key")175 address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())176 result = self.nodes[1].importmulti([{177 "scriptPubKey": address['scriptPubKey'],178 "timestamp": "now",179 "keys": [ self.nodes[0].dumpprivkey(address['address']) ],180 "internal": True181 }])182 assert_equal(result[0]['success'], True)183 address_assert = self.nodes[1].validateaddress(address['address'])184 assert_equal(address_assert['iswatchonly'], False)185 assert_equal(address_assert['ismine'], True)186 assert_equal(address_assert['timestamp'], timestamp)187 # ScriptPubKey + Private key + !internal188 self.log.info("Should not import a scriptPubKey without internal and with private key")189 address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())190 result = self.nodes[1].importmulti([{191 "scriptPubKey": address['scriptPubKey'],192 "timestamp": "now",193 "keys": [ self.nodes[0].dumpprivkey(address['address']) ]194 }])195 assert_equal(result[0]['success'], False)196 assert_equal(result[0]['error']['code'], -8)197 assert_equal(result[0]['error']['message'], 'Internal must be set for hex scriptPubKey')198 address_assert = self.nodes[1].validateaddress(address['address'])199 assert_equal(address_assert['iswatchonly'], False)200 assert_equal(address_assert['ismine'], False)201 assert_equal('timestamp' in address_assert, False)202 # P2SH address203 sig_address_1 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())204 sig_address_2 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())205 sig_address_3 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())206 multi_sig_script = self.nodes[0].createmultisig(2, [sig_address_1['address'], sig_address_2['address'], sig_address_3['pubkey']])207 self.nodes[1].generate(100)208 transactionid = self.nodes[1].sendtoaddress(multi_sig_script['address'], 10.00)209 self.nodes[1].generate(1)210 timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']211 self.log.info("Should import a p2sh")212 result = self.nodes[1].importmulti([{213 "scriptPubKey": {214 "address": multi_sig_script['address']215 },216 "timestamp": "now",217 }])218 assert_equal(result[0]['success'], True)219 address_assert = self.nodes[1].validateaddress(multi_sig_script['address'])220 assert_equal(address_assert['isscript'], True)221 assert_equal(address_assert['iswatchonly'], True)222 assert_equal(address_assert['timestamp'], timestamp)223 p2shunspent = self.nodes[1].listunspent(0,999999, [multi_sig_script['address']])[0]224 assert_equal(p2shunspent['spendable'], False)225 assert_equal(p2shunspent['solvable'], False)226 # P2SH + Redeem script227 sig_address_1 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())228 sig_address_2 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())229 sig_address_3 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())230 multi_sig_script = self.nodes[0].createmultisig(2, [sig_address_1['address'], sig_address_2['address'], sig_address_3['pubkey']])231 self.nodes[1].generate(100)232 transactionid = self.nodes[1].sendtoaddress(multi_sig_script['address'], 10.00)233 self.nodes[1].generate(1)234 timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']235 self.log.info("Should import a p2sh with respective redeem script")236 result = self.nodes[1].importmulti([{237 "scriptPubKey": {238 "address": multi_sig_script['address']239 },240 "timestamp": "now",241 "redeemscript": multi_sig_script['redeemScript']242 }])243 assert_equal(result[0]['success'], True)244 address_assert = self.nodes[1].validateaddress(multi_sig_script['address'])245 assert_equal(address_assert['timestamp'], timestamp)246 p2shunspent = self.nodes[1].listunspent(0,999999, [multi_sig_script['address']])[0]247 assert_equal(p2shunspent['spendable'], False)248 assert_equal(p2shunspent['solvable'], True)249 # P2SH + Redeem script + Private Keys + !Watchonly250 sig_address_1 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())251 sig_address_2 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())252 sig_address_3 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())253 multi_sig_script = self.nodes[0].createmultisig(2, [sig_address_1['address'], sig_address_2['address'], sig_address_3['pubkey']])254 self.nodes[1].generate(100)255 transactionid = self.nodes[1].sendtoaddress(multi_sig_script['address'], 10.00)256 self.nodes[1].generate(1)257 timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']258 self.log.info("Should import a p2sh with respective redeem script and private keys")259 result = self.nodes[1].importmulti([{260 "scriptPubKey": {261 "address": multi_sig_script['address']262 },263 "timestamp": "now",264 "redeemscript": multi_sig_script['redeemScript'],265 "keys": [ self.nodes[0].dumpprivkey(sig_address_1['address']), self.nodes[0].dumpprivkey(sig_address_2['address'])]266 }])267 assert_equal(result[0]['success'], True)268 address_assert = self.nodes[1].validateaddress(multi_sig_script['address'])269 assert_equal(address_assert['timestamp'], timestamp)270 p2shunspent = self.nodes[1].listunspent(0,999999, [multi_sig_script['address']])[0]271 assert_equal(p2shunspent['spendable'], False)272 assert_equal(p2shunspent['solvable'], True)273 # P2SH + Redeem script + Private Keys + Watchonly274 sig_address_1 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())275 sig_address_2 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())276 sig_address_3 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())277 multi_sig_script = self.nodes[0].createmultisig(2, [sig_address_1['address'], sig_address_2['address'], sig_address_3['pubkey']])278 self.nodes[1].generate(100)279 transactionid = self.nodes[1].sendtoaddress(multi_sig_script['address'], 10.00)280 self.nodes[1].generate(1)281 timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']282 self.log.info("Should import a p2sh with respective redeem script and private keys")283 result = self.nodes[1].importmulti([{284 "scriptPubKey": {285 "address": multi_sig_script['address']286 },287 "timestamp": "now",288 "redeemscript": multi_sig_script['redeemScript'],289 "keys": [ self.nodes[0].dumpprivkey(sig_address_1['address']), self.nodes[0].dumpprivkey(sig_address_2['address'])],290 "watchonly": True291 }])292 assert_equal(result[0]['success'], False)293 assert_equal(result[0]['error']['code'], -8)294 assert_equal(result[0]['error']['message'], 'Incompatibility found between watchonly and keys')295 # Address + Public key + !Internal + Wrong pubkey296 self.log.info("Should not import an address with a wrong public key")297 address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())298 address2 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())299 result = self.nodes[1].importmulti([{300 "scriptPubKey": {301 "address": address['address']302 },303 "timestamp": "now",304 "pubkeys": [ address2['pubkey'] ]305 }])306 assert_equal(result[0]['success'], False)307 assert_equal(result[0]['error']['code'], -5)308 assert_equal(result[0]['error']['message'], 'Consistency check failed')309 address_assert = self.nodes[1].validateaddress(address['address'])310 assert_equal(address_assert['iswatchonly'], False)311 assert_equal(address_assert['ismine'], False)312 assert_equal('timestamp' in address_assert, False)313 # ScriptPubKey + Public key + internal + Wrong pubkey314 self.log.info("Should not import a scriptPubKey with internal and with a wrong public key")315 address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())316 address2 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())317 request = [{318 "scriptPubKey": address['scriptPubKey'],319 "timestamp": "now",320 "pubkeys": [ address2['pubkey'] ],321 "internal": True322 }]323 result = self.nodes[1].importmulti(request)324 assert_equal(result[0]['success'], False)325 assert_equal(result[0]['error']['code'], -5)326 assert_equal(result[0]['error']['message'], 'Consistency check failed')327 address_assert = self.nodes[1].validateaddress(address['address'])328 assert_equal(address_assert['iswatchonly'], False)329 assert_equal(address_assert['ismine'], False)330 assert_equal('timestamp' in address_assert, False)331 # Address + Private key + !watchonly + Wrong private key332 self.log.info("Should not import an address with a wrong private key")333 address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())334 address2 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())335 result = self.nodes[1].importmulti([{336 "scriptPubKey": {337 "address": address['address']338 },339 "timestamp": "now",340 "keys": [ self.nodes[0].dumpprivkey(address2['address']) ]341 }])342 assert_equal(result[0]['success'], False)343 assert_equal(result[0]['error']['code'], -5)344 assert_equal(result[0]['error']['message'], 'Consistency check failed')345 address_assert = self.nodes[1].validateaddress(address['address'])346 assert_equal(address_assert['iswatchonly'], False)347 assert_equal(address_assert['ismine'], False)348 assert_equal('timestamp' in address_assert, False)349 # ScriptPubKey + Private key + internal + Wrong private key350 self.log.info("Should not import a scriptPubKey with internal and with a wrong private key")351 address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())352 address2 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())353 result = self.nodes[1].importmulti([{354 "scriptPubKey": address['scriptPubKey'],355 "timestamp": "now",356 "keys": [ self.nodes[0].dumpprivkey(address2['address']) ],357 "internal": True358 }])359 assert_equal(result[0]['success'], False)360 assert_equal(result[0]['error']['code'], -5)361 assert_equal(result[0]['error']['message'], 'Consistency check failed')362 address_assert = self.nodes[1].validateaddress(address['address'])363 assert_equal(address_assert['iswatchonly'], False)364 assert_equal(address_assert['ismine'], False)365 assert_equal('timestamp' in address_assert, False)366 # Importing existing watch only address with new timestamp should replace saved timestamp.367 assert_greater_than(timestamp, watchonly_timestamp)368 self.log.info("Should replace previously saved watch only timestamp.")369 result = self.nodes[1].importmulti([{370 "scriptPubKey": {371 "address": watchonly_address,372 },373 "timestamp": "now",374 }])375 assert_equal(result[0]['success'], True)376 address_assert = self.nodes[1].validateaddress(watchonly_address)377 assert_equal(address_assert['iswatchonly'], True)378 assert_equal(address_assert['ismine'], False)379 assert_equal(address_assert['timestamp'], timestamp)380 watchonly_timestamp = timestamp381 # restart nodes to check for proper serialization/deserialization of watch only address382 self.stop_nodes()383 self.start_nodes()384 address_assert = self.nodes[1].validateaddress(watchonly_address)385 assert_equal(address_assert['iswatchonly'], True)386 assert_equal(address_assert['ismine'], False)387 assert_equal(address_assert['timestamp'], watchonly_timestamp)388 # Bad or missing timestamps389 self.log.info("Should throw on invalid or missing timestamp values")390 assert_raises_rpc_error(-3, 'Missing required timestamp field for key',391 self.nodes[1].importmulti, [{392 "scriptPubKey": address['scriptPubKey'],393 }])394 assert_raises_rpc_error(-3, 'Expected number or "now" timestamp value for key. got type string',395 self.nodes[1].importmulti, [{396 "scriptPubKey": address['scriptPubKey'],397 "timestamp": "",398 }])...
wallet_importmulti.py
Source:wallet_importmulti.py
...16 self.log.info("Mining blocks...")17 self.nodes[0].generate(1)18 self.nodes[1].generate(1)19 timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']20 node0_address1 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())21 #Check only one address22 assert_equal(node0_address1['ismine'], True)23 #Node 1 sync test24 assert_equal(self.nodes[1].getblockcount(),1)25 #Address Test - before import26 address_info = self.nodes[1].validateaddress(node0_address1['address'])27 assert_equal(address_info['iswatchonly'], False)28 assert_equal(address_info['ismine'], False)29 # RPC importmulti -----------------------------------------------30 # Bitcoin Address31 self.log.info("Should import an address")32 address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())33 result = self.nodes[1].importmulti([{34 "scriptPubKey": {35 "address": address['address']36 },37 "timestamp": "now",38 }])39 assert_equal(result[0]['success'], True)40 address_assert = self.nodes[1].validateaddress(address['address'])41 assert_equal(address_assert['iswatchonly'], True)42 assert_equal(address_assert['ismine'], False)43 assert_equal(address_assert['timestamp'], timestamp)44 watchonly_address = address['address']45 watchonly_timestamp = timestamp46 self.log.info("Should not import an invalid address")47 result = self.nodes[1].importmulti([{48 "scriptPubKey": {49 "address": "not valid address",50 },51 "timestamp": "now",52 }])53 assert_equal(result[0]['success'], False)54 assert_equal(result[0]['error']['code'], -5)55 assert_equal(result[0]['error']['message'], 'Invalid address')56 # ScriptPubKey + internal57 self.log.info("Should import a scriptPubKey with internal flag")58 address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())59 result = self.nodes[1].importmulti([{60 "scriptPubKey": address['scriptPubKey'],61 "timestamp": "now",62 "internal": True63 }])64 assert_equal(result[0]['success'], True)65 address_assert = self.nodes[1].validateaddress(address['address'])66 assert_equal(address_assert['iswatchonly'], True)67 assert_equal(address_assert['ismine'], False)68 assert_equal(address_assert['timestamp'], timestamp)69 # ScriptPubKey + !internal70 self.log.info("Should not import a scriptPubKey without internal flag")71 address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())72 result = self.nodes[1].importmulti([{73 "scriptPubKey": address['scriptPubKey'],74 "timestamp": "now",75 }])76 assert_equal(result[0]['success'], False)77 assert_equal(result[0]['error']['code'], -8)78 assert_equal(result[0]['error']['message'], 'Internal must be set for hex scriptPubKey')79 address_assert = self.nodes[1].validateaddress(address['address'])80 assert_equal(address_assert['iswatchonly'], False)81 assert_equal(address_assert['ismine'], False)82 assert_equal('timestamp' in address_assert, False)83 # Address + Public key + !Internal84 self.log.info("Should import an address with public key")85 address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())86 result = self.nodes[1].importmulti([{87 "scriptPubKey": {88 "address": address['address']89 },90 "timestamp": "now",91 "pubkeys": [ address['pubkey'] ]92 }])93 assert_equal(result[0]['success'], True)94 address_assert = self.nodes[1].validateaddress(address['address'])95 assert_equal(address_assert['iswatchonly'], True)96 assert_equal(address_assert['ismine'], False)97 assert_equal(address_assert['timestamp'], timestamp)98 # ScriptPubKey + Public key + internal99 self.log.info("Should import a scriptPubKey with internal and with public key")100 address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())101 request = [{102 "scriptPubKey": address['scriptPubKey'],103 "timestamp": "now",104 "pubkeys": [ address['pubkey'] ],105 "internal": True106 }]107 result = self.nodes[1].importmulti(request)108 assert_equal(result[0]['success'], True)109 address_assert = self.nodes[1].validateaddress(address['address'])110 assert_equal(address_assert['iswatchonly'], True)111 assert_equal(address_assert['ismine'], False)112 assert_equal(address_assert['timestamp'], timestamp)113 # ScriptPubKey + Public key + !internal114 self.log.info("Should not import a scriptPubKey without internal and with public key")115 address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())116 request = [{117 "scriptPubKey": address['scriptPubKey'],118 "timestamp": "now",119 "pubkeys": [ address['pubkey'] ]120 }]121 result = self.nodes[1].importmulti(request)122 assert_equal(result[0]['success'], False)123 assert_equal(result[0]['error']['code'], -8)124 assert_equal(result[0]['error']['message'], 'Internal must be set for hex scriptPubKey')125 address_assert = self.nodes[1].validateaddress(address['address'])126 assert_equal(address_assert['iswatchonly'], False)127 assert_equal(address_assert['ismine'], False)128 assert_equal('timestamp' in address_assert, False)129 # Address + Private key + !watchonly130 self.log.info("Should import an address with private key")131 address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())132 result = self.nodes[1].importmulti([{133 "scriptPubKey": {134 "address": address['address']135 },136 "timestamp": "now",137 "keys": [ self.nodes[0].dumpprivkey(address['address']) ]138 }])139 assert_equal(result[0]['success'], True)140 address_assert = self.nodes[1].validateaddress(address['address'])141 assert_equal(address_assert['iswatchonly'], False)142 assert_equal(address_assert['ismine'], True)143 assert_equal(address_assert['timestamp'], timestamp)144 self.log.info("Should not import an address with private key if is already imported")145 result = self.nodes[1].importmulti([{146 "scriptPubKey": {147 "address": address['address']148 },149 "timestamp": "now",150 "keys": [ self.nodes[0].dumpprivkey(address['address']) ]151 }])152 assert_equal(result[0]['success'], False)153 assert_equal(result[0]['error']['code'], -4)154 assert_equal(result[0]['error']['message'], 'The wallet already contains the private key for this address or script')155 # Address + Private key + watchonly156 self.log.info("Should not import an address with private key and with watchonly")157 address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())158 result = self.nodes[1].importmulti([{159 "scriptPubKey": {160 "address": address['address']161 },162 "timestamp": "now",163 "keys": [ self.nodes[0].dumpprivkey(address['address']) ],164 "watchonly": True165 }])166 assert_equal(result[0]['success'], False)167 assert_equal(result[0]['error']['code'], -8)168 assert_equal(result[0]['error']['message'], 'Incompatibility found between watchonly and keys')169 address_assert = self.nodes[1].validateaddress(address['address'])170 assert_equal(address_assert['iswatchonly'], False)171 assert_equal(address_assert['ismine'], False)172 assert_equal('timestamp' in address_assert, False)173 # ScriptPubKey + Private key + internal174 self.log.info("Should import a scriptPubKey with internal and with private key")175 address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())176 result = self.nodes[1].importmulti([{177 "scriptPubKey": address['scriptPubKey'],178 "timestamp": "now",179 "keys": [ self.nodes[0].dumpprivkey(address['address']) ],180 "internal": True181 }])182 assert_equal(result[0]['success'], True)183 address_assert = self.nodes[1].validateaddress(address['address'])184 assert_equal(address_assert['iswatchonly'], False)185 assert_equal(address_assert['ismine'], True)186 assert_equal(address_assert['timestamp'], timestamp)187 # ScriptPubKey + Private key + !internal188 self.log.info("Should not import a scriptPubKey without internal and with private key")189 address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())190 result = self.nodes[1].importmulti([{191 "scriptPubKey": address['scriptPubKey'],192 "timestamp": "now",193 "keys": [ self.nodes[0].dumpprivkey(address['address']) ]194 }])195 assert_equal(result[0]['success'], False)196 assert_equal(result[0]['error']['code'], -8)197 assert_equal(result[0]['error']['message'], 'Internal must be set for hex scriptPubKey')198 address_assert = self.nodes[1].validateaddress(address['address'])199 assert_equal(address_assert['iswatchonly'], False)200 assert_equal(address_assert['ismine'], False)201 assert_equal('timestamp' in address_assert, False)202 # P2SH address203 sig_address_1 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())204 sig_address_2 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())205 sig_address_3 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())206 multi_sig_script = self.nodes[0].createmultisig(2, [sig_address_1['pubkey'], sig_address_2['pubkey'], sig_address_3['pubkey']])207 self.nodes[1].generate(100)208 transactionid = self.nodes[1].sendtoaddress(multi_sig_script['address'], 10.00)209 self.nodes[1].generate(1)210 timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']211 self.log.info("Should import a p2sh")212 result = self.nodes[1].importmulti([{213 "scriptPubKey": {214 "address": multi_sig_script['address']215 },216 "timestamp": "now",217 }])218 assert_equal(result[0]['success'], True)219 address_assert = self.nodes[1].validateaddress(multi_sig_script['address'])220 assert_equal(address_assert['isscript'], True)221 assert_equal(address_assert['iswatchonly'], True)222 assert_equal(address_assert['timestamp'], timestamp)223 p2shunspent = self.nodes[1].listunspent(0,999999, [multi_sig_script['address']])[0]224 assert_equal(p2shunspent['spendable'], False)225 assert_equal(p2shunspent['solvable'], False)226 # P2SH + Redeem script227 sig_address_1 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())228 sig_address_2 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())229 sig_address_3 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())230 multi_sig_script = self.nodes[0].createmultisig(2, [sig_address_1['pubkey'], sig_address_2['pubkey'], sig_address_3['pubkey']])231 self.nodes[1].generate(100)232 transactionid = self.nodes[1].sendtoaddress(multi_sig_script['address'], 10.00)233 self.nodes[1].generate(1)234 timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']235 self.log.info("Should import a p2sh with respective redeem script")236 result = self.nodes[1].importmulti([{237 "scriptPubKey": {238 "address": multi_sig_script['address']239 },240 "timestamp": "now",241 "redeemscript": multi_sig_script['redeemScript']242 }])243 assert_equal(result[0]['success'], True)244 address_assert = self.nodes[1].validateaddress(multi_sig_script['address'])245 assert_equal(address_assert['timestamp'], timestamp)246 p2shunspent = self.nodes[1].listunspent(0,999999, [multi_sig_script['address']])[0]247 assert_equal(p2shunspent['spendable'], False)248 assert_equal(p2shunspent['solvable'], True)249 # P2SH + Redeem script + Private Keys + !Watchonly250 sig_address_1 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())251 sig_address_2 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())252 sig_address_3 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())253 multi_sig_script = self.nodes[0].createmultisig(2, [sig_address_1['pubkey'], sig_address_2['pubkey'], sig_address_3['pubkey']])254 self.nodes[1].generate(100)255 transactionid = self.nodes[1].sendtoaddress(multi_sig_script['address'], 10.00)256 self.nodes[1].generate(1)257 timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']258 self.log.info("Should import a p2sh with respective redeem script and private keys")259 result = self.nodes[1].importmulti([{260 "scriptPubKey": {261 "address": multi_sig_script['address']262 },263 "timestamp": "now",264 "redeemscript": multi_sig_script['redeemScript'],265 "keys": [ self.nodes[0].dumpprivkey(sig_address_1['address']), self.nodes[0].dumpprivkey(sig_address_2['address'])]266 }])267 assert_equal(result[0]['success'], True)268 address_assert = self.nodes[1].validateaddress(multi_sig_script['address'])269 assert_equal(address_assert['timestamp'], timestamp)270 p2shunspent = self.nodes[1].listunspent(0,999999, [multi_sig_script['address']])[0]271 assert_equal(p2shunspent['spendable'], False)272 assert_equal(p2shunspent['solvable'], True)273 # P2SH + Redeem script + Private Keys + Watchonly274 sig_address_1 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())275 sig_address_2 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())276 sig_address_3 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())277 multi_sig_script = self.nodes[0].createmultisig(2, [sig_address_1['pubkey'], sig_address_2['pubkey'], sig_address_3['pubkey']])278 self.nodes[1].generate(100)279 transactionid = self.nodes[1].sendtoaddress(multi_sig_script['address'], 10.00)280 self.nodes[1].generate(1)281 timestamp = self.nodes[1].getblock(self.nodes[1].getbestblockhash())['mediantime']282 self.log.info("Should import a p2sh with respective redeem script and private keys")283 result = self.nodes[1].importmulti([{284 "scriptPubKey": {285 "address": multi_sig_script['address']286 },287 "timestamp": "now",288 "redeemscript": multi_sig_script['redeemScript'],289 "keys": [ self.nodes[0].dumpprivkey(sig_address_1['address']), self.nodes[0].dumpprivkey(sig_address_2['address'])],290 "watchonly": True291 }])292 assert_equal(result[0]['success'], False)293 assert_equal(result[0]['error']['code'], -8)294 assert_equal(result[0]['error']['message'], 'Incompatibility found between watchonly and keys')295 # Address + Public key + !Internal + Wrong pubkey296 self.log.info("Should not import an address with a wrong public key")297 address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())298 address2 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())299 result = self.nodes[1].importmulti([{300 "scriptPubKey": {301 "address": address['address']302 },303 "timestamp": "now",304 "pubkeys": [ address2['pubkey'] ]305 }])306 assert_equal(result[0]['success'], False)307 assert_equal(result[0]['error']['code'], -5)308 assert_equal(result[0]['error']['message'], 'Consistency check failed')309 address_assert = self.nodes[1].validateaddress(address['address'])310 assert_equal(address_assert['iswatchonly'], False)311 assert_equal(address_assert['ismine'], False)312 assert_equal('timestamp' in address_assert, False)313 # ScriptPubKey + Public key + internal + Wrong pubkey314 self.log.info("Should not import a scriptPubKey with internal and with a wrong public key")315 address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())316 address2 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())317 request = [{318 "scriptPubKey": address['scriptPubKey'],319 "timestamp": "now",320 "pubkeys": [ address2['pubkey'] ],321 "internal": True322 }]323 result = self.nodes[1].importmulti(request)324 assert_equal(result[0]['success'], False)325 assert_equal(result[0]['error']['code'], -5)326 assert_equal(result[0]['error']['message'], 'Consistency check failed')327 address_assert = self.nodes[1].validateaddress(address['address'])328 assert_equal(address_assert['iswatchonly'], False)329 assert_equal(address_assert['ismine'], False)330 assert_equal('timestamp' in address_assert, False)331 # Address + Private key + !watchonly + Wrong private key332 self.log.info("Should not import an address with a wrong private key")333 address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())334 address2 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())335 result = self.nodes[1].importmulti([{336 "scriptPubKey": {337 "address": address['address']338 },339 "timestamp": "now",340 "keys": [ self.nodes[0].dumpprivkey(address2['address']) ]341 }])342 assert_equal(result[0]['success'], False)343 assert_equal(result[0]['error']['code'], -5)344 assert_equal(result[0]['error']['message'], 'Consistency check failed')345 address_assert = self.nodes[1].validateaddress(address['address'])346 assert_equal(address_assert['iswatchonly'], False)347 assert_equal(address_assert['ismine'], False)348 assert_equal('timestamp' in address_assert, False)349 # ScriptPubKey + Private key + internal + Wrong private key350 self.log.info("Should not import a scriptPubKey with internal and with a wrong private key")351 address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())352 address2 = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())353 result = self.nodes[1].importmulti([{354 "scriptPubKey": address['scriptPubKey'],355 "timestamp": "now",356 "keys": [ self.nodes[0].dumpprivkey(address2['address']) ],357 "internal": True358 }])359 assert_equal(result[0]['success'], False)360 assert_equal(result[0]['error']['code'], -5)361 assert_equal(result[0]['error']['message'], 'Consistency check failed')362 address_assert = self.nodes[1].validateaddress(address['address'])363 assert_equal(address_assert['iswatchonly'], False)364 assert_equal(address_assert['ismine'], False)365 assert_equal('timestamp' in address_assert, False)366 # Importing existing watch only address with new timestamp should replace saved timestamp.367 assert_greater_than(timestamp, watchonly_timestamp)368 self.log.info("Should replace previously saved watch only timestamp.")369 result = self.nodes[1].importmulti([{370 "scriptPubKey": {371 "address": watchonly_address,372 },373 "timestamp": "now",374 }])375 assert_equal(result[0]['success'], True)376 address_assert = self.nodes[1].validateaddress(watchonly_address)377 assert_equal(address_assert['iswatchonly'], True)378 assert_equal(address_assert['ismine'], False)379 assert_equal(address_assert['timestamp'], timestamp)380 watchonly_timestamp = timestamp381 # restart nodes to check for proper serialization/deserialization of watch only address382 self.stop_nodes()383 self.start_nodes()384 address_assert = self.nodes[1].validateaddress(watchonly_address)385 assert_equal(address_assert['iswatchonly'], True)386 assert_equal(address_assert['ismine'], False)387 assert_equal(address_assert['timestamp'], watchonly_timestamp)388 # Bad or missing timestamps389 self.log.info("Should throw on invalid or missing timestamp values")390 assert_raises_rpc_error(-3, 'Missing required timestamp field for key',391 self.nodes[1].importmulti, [{392 "scriptPubKey": address['scriptPubKey'],393 }])394 assert_raises_rpc_error(-3, 'Expected number or "now" timestamp value for key. got type string',395 self.nodes[1].importmulti, [{396 "scriptPubKey": address['scriptPubKey'],397 "timestamp": "",398 }])...
checkout-data-resolver.js
Source:checkout-data-resolver.js
1/**2 * Copyright © 2015 Magento. All rights reserved.3 * See COPYING.txt for license details.4 */5/*jshint browser:true*/6/*global alert*/7/**8 * Checkout adapter for customer data storage9 */10define(11 [12 'Magento_Customer/js/model/address-list',13 'Magento_Checkout/js/model/quote',14 'Magento_Checkout/js/checkout-data',15 'Magento_Checkout/js/action/create-shipping-address',16 'Magento_Checkout/js/action/select-shipping-address',17 'Magento_Checkout/js/action/select-shipping-method',18 'Magento_Checkout/js/model/payment-service',19 'Magento_Checkout/js/action/select-payment-method',20 'Magento_Checkout/js/model/address-converter',21 'Magento_Checkout/js/action/select-billing-address',22 'Magento_Checkout/js/action/create-billing-address',23 'underscore'24 ],25 function (26 addressList,27 quote,28 checkoutData,29 createShippingAddress,30 selectShippingAddress,31 selectShippingMethodAction,32 paymentService,33 selectPaymentMethodAction,34 addressConverter,35 selectBillingAddress,36 createBillingAddress,37 _38 ) {39 'use strict';40 return {41 /**42 * Resolve estimation address. Used local storage43 */44 resolveEstimationAddress: function () {45 var address;46 if (checkoutData.getShippingAddressFromData()) {47 address = addressConverter.formAddressDataToQuoteAddress(checkoutData.getShippingAddressFromData());48 selectShippingAddress(address);49 } else {50 this.resolveShippingAddress();51 }52 if (quote.isVirtual()) {53 if (checkoutData.getBillingAddressFromData()) {54 address = addressConverter.formAddressDataToQuoteAddress(55 checkoutData.getBillingAddressFromData()56 );57 selectBillingAddress(address);58 } else {59 this.resolveBillingAddress();60 }61 }62 },63 /**64 * Resolve shipping address. Used local storage65 */66 resolveShippingAddress: function () {67 var newCustomerShippingAddress = checkoutData.getNewCustomerShippingAddress();68 if (newCustomerShippingAddress) {69 createShippingAddress(newCustomerShippingAddress);70 }71 this.applyShippingAddress();72 },73 /**74 * Apply resolved estimated address to quote75 *76 * @param {Object} isEstimatedAddress77 */78 applyShippingAddress: function (isEstimatedAddress) {79 var address,80 shippingAddress,81 isConvertAddress,82 addressData,83 isShippingAddressInitialized;84 if (addressList().length == 0) {85 address = addressConverter.formAddressDataToQuoteAddress(86 checkoutData.getShippingAddressFromData()87 );88 selectShippingAddress(address);89 }90 shippingAddress = quote.shippingAddress();91 isConvertAddress = isEstimatedAddress || false;92 if (!shippingAddress) {93 isShippingAddressInitialized = addressList.some(function (addressFromList) {94 if (checkoutData.getSelectedShippingAddress() == addressFromList.getKey()) {95 addressData = isConvertAddress ?96 addressConverter.addressToEstimationAddress(addressFromList)97 : addressFromList;98 selectShippingAddress(addressData);99 return true;100 }101 return false;102 });103 if (!isShippingAddressInitialized) {104 isShippingAddressInitialized = addressList.some(function (address) {105 if (address.isDefaultShipping()) {106 addressData = isConvertAddress ?107 addressConverter.addressToEstimationAddress(address)108 : address;109 selectShippingAddress(addressData);110 return true;111 }112 return false;113 });114 }115 if (!isShippingAddressInitialized && addressList().length == 1) {116 addressData = isConvertAddress ?117 addressConverter.addressToEstimationAddress(addressList()[0])118 : addressList()[0];119 selectShippingAddress(addressData);120 }121 }122 },123 /**124 * @param {Object} ratesData125 */126 resolveShippingRates: function (ratesData) {127 var selectedShippingRate = checkoutData.getSelectedShippingRate(),128 availableRate = false;129 if (ratesData.length == 1) {130 //set shipping rate if we have only one available shipping rate131 selectShippingMethodAction(ratesData[0]);132 return;133 }134 if (quote.shippingMethod()) {135 availableRate = _.find(ratesData, function (rate) {136 return rate.carrier_code == quote.shippingMethod().carrier_code &&137 rate.method_code == quote.shippingMethod().method_code;138 });139 }140 if (!availableRate && selectedShippingRate) {141 availableRate = _.find(ratesData, function (rate) {142 return rate.carrier_code + '_' + rate.method_code === selectedShippingRate;143 });144 }145 if (!availableRate && window.checkoutConfig.selectedShippingMethod) {146 availableRate = true;147 selectShippingMethodAction(window.checkoutConfig.selectedShippingMethod);148 }149 //Unset selected shipping method if not available150 if (!availableRate) {151 selectShippingMethodAction(null);152 } else {153 selectShippingMethodAction(availableRate);154 }155 },156 /**157 * Resolve payment method. Used local storage158 */159 resolvePaymentMethod: function () {160 var availablePaymentMethods = paymentService.getAvailablePaymentMethods(),161 selectedPaymentMethod = checkoutData.getSelectedPaymentMethod();162 if (selectedPaymentMethod) {163 availablePaymentMethods.some(function (payment) {164 if (payment.method == selectedPaymentMethod) {165 selectPaymentMethodAction(payment);166 }167 });168 }169 },170 /**171 * Resolve billing address. Used local storage172 */173 resolveBillingAddress: function () {174 var selectedBillingAddress = checkoutData.getSelectedBillingAddress(),175 newCustomerBillingAddressData = checkoutData.getNewCustomerBillingAddress();176 if (selectedBillingAddress) {177 if (selectedBillingAddress == 'new-customer-address' && newCustomerBillingAddressData) {178 selectBillingAddress(createBillingAddress(newCustomerBillingAddressData));179 } else {180 addressList.some(function (address) {181 if (selectedBillingAddress == address.getKey()) {182 selectBillingAddress(address);183 }184 });185 }186 } else {187 this.applyBillingAddress();188 }189 },190 /**191 * Apply resolved billing address to quote192 */193 applyBillingAddress: function () {194 var shippingAddress;195 if (quote.billingAddress()) {196 selectBillingAddress(quote.billingAddress());197 return;198 }199 shippingAddress = quote.shippingAddress();200 if (shippingAddress &&201 shippingAddress.canUseForBilling() &&202 (shippingAddress.isDefaultShipping() || !quote.isVirtual())203 ) {204 //set billing address same as shipping by default if it is not empty205 selectBillingAddress(quote.shippingAddress());206 }207 }208 };209 }...
wallet_accounts.py
Source:wallet_accounts.py
...67 # Create accounts and make sure subsequent account API calls68 # recognize the account/address associations.69 accounts = [Account(name) for name in ("a", "b", "c", "d", "e")]70 for account in accounts:71 account.add_receive_address(node.getaccountaddress(account.name))72 account.verify(node)73 # Send a transaction to each account, and make sure this forces74 # getaccountaddress to generate a new receiving address.75 for account in accounts:76 node.sendtoaddress(account.receive_address, amount_to_send)77 account.add_receive_address(node.getaccountaddress(account.name))78 account.verify(node)79 # Check the amounts received.80 node.generate(1)81 for account in accounts:82 assert_equal(83 node.getreceivedbyaddress(account.addresses[0]), amount_to_send)84 assert_equal(node.getreceivedbyaccount(account.name), amount_to_send)85 86 # Check that sendfrom account reduces listaccounts balances.87 for i, account in enumerate(accounts):88 to_account = accounts[(i+1) % len(accounts)]89 node.sendfrom(account.name, to_account.receive_address, amount_to_send)90 node.generate(1)91 for account in accounts:92 account.add_receive_address(node.getaccountaddress(account.name))93 account.verify(node)94 assert_equal(node.getreceivedbyaccount(account.name), 2)95 node.move(account.name, "", node.getbalance(account.name))96 account.verify(node)97 node.generate(101)98 expected_account_balances = {"": 5200}99 for account in accounts:100 expected_account_balances[account.name] = 0101 assert_equal(node.listaccounts(), expected_account_balances)102 assert_equal(node.getbalance(""), 5200)103 104 # Check that setaccount can assign an account to a new unused address.105 for account in accounts:106 address = node.getaccountaddress("")107 node.setaccount(address, account.name)108 account.add_address(address)109 account.verify(node)110 assert(address not in node.getaddressesbyaccount(""))111 112 # Check that addmultisigaddress can assign accounts.113 for account in accounts:114 addresses = []115 for x in range(10):116 addresses.append(node.getnewaddress())117 multisig_address = node.addmultisigaddress(5, addresses, account.name)['address']118 account.add_address(multisig_address)119 account.verify(node)120 node.sendfrom("", multisig_address, 50)121 node.generate(101)122 for account in accounts:123 assert_equal(node.getbalance(account.name), 50)124 # Check that setaccount can change the account of an address from a125 # different account.126 change_account(node, accounts[0].addresses[0], accounts[0], accounts[1])127 # Check that setaccount can change the account of an address which128 # is the receiving address of a different account.129 change_account(node, accounts[0].receive_address, accounts[0], accounts[1])130 # Check that setaccount can set the account of an address already131 # in the account. This is a no-op.132 change_account(node, accounts[2].addresses[0], accounts[2], accounts[2])133 # Check that setaccount can set the account of an address which is134 # already the receiving address of the account. It would probably make135 # sense for this to be a no-op, but right now it resets the receiving136 # address, causing getaccountaddress to return a brand new address.137 change_account(node, accounts[2].receive_address, accounts[2], accounts[2])138class Account:139 def __init__(self, name):140 # Account name141 self.name = name142 # Current receiving address associated with this account.143 self.receive_address = None144 # List of all addresses assigned with this account145 self.addresses = []146 def add_address(self, address):147 assert_equal(address not in self.addresses, True)148 self.addresses.append(address)149 def add_receive_address(self, address):150 self.add_address(address)151 self.receive_address = address152 def verify(self, node):153 if self.receive_address is not None:154 assert self.receive_address in self.addresses155 assert_equal(node.getaccountaddress(self.name), self.receive_address)156 for address in self.addresses:157 assert_equal(node.getaccount(address), self.name)158 assert_equal(159 set(node.getaddressesbyaccount(self.name)), set(self.addresses))160def change_account(node, address, old_account, new_account):161 assert_equal(address in old_account.addresses, True)162 node.setaccount(address, new_account.name)163 old_account.addresses.remove(address)164 new_account.add_address(address)165 # Calling setaccount on an address which was previously the receiving166 # address of a different account should reset the receiving address of167 # the old account, causing getaccountaddress to return a brand new168 # address.169 if address == old_account.receive_address:170 new_address = node.getaccountaddress(old_account.name)171 assert_equal(new_address not in old_account.addresses, True)172 assert_equal(new_address not in new_account.addresses, True)173 old_account.add_receive_address(new_address)174 old_account.verify(node)175 new_account.verify(node)176if __name__ == '__main__':...
AssignEventAddresses.js
Source:AssignEventAddresses.js
1/**2 * Handles Pipeline call for assignEventAddresses3 *4 * @input ProductList : dw.customer.ProductList The product list representing the gift registry.5 * @input GiftRegistryForm : dw.web.FormGroup The form definition representing the gift registry.6 * @input Customer : dw.customer.Customer The current customer's addressbook.7 *8 */9function execute(pdict) {10 assignEventAddresses(pdict);11 return PIPELET_NEXT;12}13/**14 * This script assigns the addresses used for the gift registry event. There are two addresses:15 * the address to use before the event occurs and the address to use after the event occurs.16 * If necessary, new addresses are created.17 *18 * This script is using form object definitions and form value definitions defined in19 * in the giftregistry.xml form. To access objects defined in a form, you use a script20 * expression.21 *22 * @param {dw.system.PipelineDictionary} pdict23 *24 */25function assignEventAddresses(pdict) {26 var productList = pdict.ProductList;27 var giftRegistryForm = pdict.GiftRegistryForm;28 var customer = pdict.Customer;29 var afterAddressId;30 var beforeAddressId;31 var addressBook = customer.getProfile().getAddressBook();32 // check to see if the before event address was changed by the user33 var addressBeforeEvent = giftRegistryForm.eventaddress.addressBeforeEvent;34 var addressBeforeEventId = addressBeforeEvent.addressid.value;35 var hasChangedBeforeAddress = isAddressChanged(addressBeforeEvent, addressBook.getAddress(addressBeforeEventId));36 // if the before event address was changed add it to the address book37 if (hasChangedBeforeAddress) {38 beforeAddressId = determineAddressId(addressBeforeEvent, addressBook);39 if(beforeAddressId) {40 addAddress(addressBeforeEvent, addressBook, beforeAddressId);41 }42 }43 // set the before address event44 if (beforeAddressId) {45 productList.setShippingAddress(addressBook.getAddress(beforeAddressId));46 } else {47 productList.setShippingAddress(addressBook.getAddress(addressBeforeEventId));48 }49 // check to see if the after event address was changed by the user50 var addressAfterEvent = giftRegistryForm.eventaddress.addressAfterEvent;51 var addressAfterEventId = addressAfterEvent.addressid.value;52 var hasChangedAfterAddress = isAddressChanged(addressAfterEvent, addressBook.getAddress(addressAfterEventId));53 // if the after event address was changed add it to the address book54 if (hasChangedAfterAddress) {55 afterAddressId = determineAddressId(addressAfterEvent, addressBook);56 if (afterAddressId) {57 addAddress(addressAfterEvent, addressBook, afterAddressId);58 }59 }60 // set the after address event61 if (afterAddressId) {62 productList.setPostEventShippingAddress(addressBook.getAddress(afterAddressId));63 } else {64 productList.setPostEventShippingAddress(addressBook.getAddress(addressAfterEventId));65 }66}67/**68 * Add a new address to the address book.69 *70 * @param {dw.web.FormGroup} addressFields71 * @param {dw.customer.CustomerAddress} address72 *73 */74function determineAddressId(addressFields, addressBook) {75 var addressID;76 var candidateID;77 var counter = 0;78 var existingAddress;79 if (addressFields.addressid.value) {80 addressID = addressFields.addressid.value;81 if (addressBook.getAddress(addressID)) {82 addressID = addressFields.city.value;83 }84 } else {85 addressID = addressFields.city.value;86 }87 candidateID = addressID;88 while (!existingAddress) {89 existingAddress = addressBook.getAddress(candidateID);90 if (existingAddress) {91 // this ID is already taken, increment the counter92 // and try the next one93 if (isAddressChanged(addressFields, existingAddress)) {94 counter++;95 candidateID = addressFields.city.value + "-" + counter;96 existingAddress = null;97 } else {98 return null;99 }100 } else {101 return candidateID;102 }103 }104}105function addAddress(addressFields, addressBook, addressID) {106 var address;107 // create the new address and copy the form values108 address = addressBook.createAddress( addressID );109 address.setFirstName( addressFields.firstname.value );110 address.setLastName( addressFields.lastname.value );111 address.setAddress1( addressFields.address1.value );112 address.setAddress2( addressFields.address2.value );113 address.setCity( addressFields.city.value );114 address.setPostalCode( addressFields.postal.value );115 address.setStateCode( addressFields.states.state.value );116 address.setCountryCode( addressFields.country.value );117 address.setPhone( addressFields.phone.value );118}119/**120 * Compare a form address with an address from the address book.121 * Return true if they are different.122 *123 * @param {dw.web.FormGroup} addressFields124 * @param {dw.customer.CustomerAddress} address125 */126function isAddressChanged(addressFields, address) {127 if (address == null) return true;128 if ( addressFields.firstname.value != address.firstName ) {129 return true;130 }131 if ( addressFields.lastname.value != address.lastName ) {132 return true;133 }134 if ( addressFields.address1.value != address.address1 ) {135 return true;136 }137 if ( addressFields.address2.value != address.address2 ) {138 return true;139 }140 if ( addressFields.city.value != address.city ) {141 return true;142 }143 if ( addressFields.postal.value != address.postalCode ) {144 return true;145 }146 if ( addressFields.states.state.value != address.stateCode ) {147 return true;148 }149 if ( addressFields.country.value != address.countryCode) {150 return true;151 }152 if ( addressFields.phone.value != address.phone ) {153 return true;154 }155 return false;156}157module.exports = {158 execute: execute,159 assignEventAddresses: assignEventAddresses...
address.repository.ts
Source:address.repository.ts
1import { Repository, EntityRepository } from 'typeorm';2import { Query, Logger, InternalServerErrorException } from '@nestjs/common';3import { CreateAddressInput } from './dto/create_address.input';4import { Address } from './address.entity';5import { Person } from '../person/person.entity';6import { UpdateAddressInput } from './dto/update_address.input';78@EntityRepository(Address)9export class AddressRepository extends Repository<Address> {10 private logger = new Logger('AddressRepository');11 12 // Address13 async build( rAddress: CreateAddressInput ): Promise<Address> {14 15 console.log('AddressRepository: Address => rData: ', rAddress);1617 const fPerson = await Person.findOneOrFail(rAddress.person_id);18 19 const nAddress = new Address();2021 Object.assign(nAddress, rAddress);2223 nAddress.person = fPerson;2425 const gAddress = await Address.save(nAddress);2627 return gAddress; // includs Person2829 // // wether we have such a person with person_id30 // try {31 // const fPerson = await Person.findOne(rAddress.person_id);32 // console.log('fPerson: ', fPerson);3334 // nAddress.person = fPerson;3536 // } catch (error) {37 // this.logger.error(38 // `!> Failed to fetch person by id: ${JSON.stringify(rAddress.person_id)} ;`,39 // error.stack,40 // );41 // throw new InternalServerErrorException({42 // message: '!> Failed to fetch person',43 // origin: '@address.repository.ts',44 // person_id: rAddress.person_id,45 // });46 // }4748 // nAddress.address_title = rAddress.address_title;49 // nAddress.address_line1 = rAddress.address_line1;50 // nAddress.address_line2 = rAddress.address_line2;51 // nAddress.location = rAddress.location;52 // nAddress.postal_code = rAddress.postal_code;53 // nAddress.city = rAddress.city;54 // nAddress.state = rAddress.state;55 // nAddress.country = rAddress.country;56 // nAddress.email = rAddress.email;57 // nAddress.phone = rAddress.phone;58 // nAddress.fax = rAddress.fax;59 60 // // save Address61 // try {62 // const gAddress = await nAddress.save();63 // console.log('gAddress: ', gAddress);64 // return gAddress;65 // } catch (error) {66 // this.logger.error(67 // `!> Failed to save address: ${JSON.stringify(rAddress)} ;`,68 // error.stack,69 // );70 // throw new InternalServerErrorException({71 // message: '!> Failed to save address',72 // origin: '@address.repository.ts',73 // address: rAddress,74 // error: error.stack,75 // });76 // }7778 }79 80 // Get81 async fetchById( rId: number ): Promise<Address> {82 // console.log('AddressRepository rId: ', rId);8384 const fAddress = await Address.findOne({ 85 relations: ["person"],86 where: { address_id: rId },87 });88 return fAddress;8990 // try {91 // const fAddress = await Address.findOne(rId);92 // console.log('fAddress: ', fAddress);9394 // return fAddress;9596 // } catch (error) {97 // this.logger.error(98 // `!> Failed to fetch address by id: ${JSON.stringify(rId)} ;`,99 // error.stack,100 // );101 // throw new InternalServerErrorException({102 // message: '!> Failed to fetch address',103 // origin: '@address.repository.ts',104 // address_id: rId,105 // });106 // }107108109 } // Address End110111 // Update112 async rebuild( rAddress: UpdateAddressInput ): Promise<Address> {113 114 // console.log('AddressRepository: Address => rData: ', rAddress);115116 const fAddress = await Address.findOneOrFail(rAddress.address_id)117118 const tuAddress = Object.assign(fAddress, rAddress);119120 // console.log('<<uS>> tuAddress:', tuAddress);121122 await Address.save(tuAddress);123124 const address = this.fetchById(rAddress.address_id)125126 return address;127 128 // nAddress.address_id = rAddress.address_id;129 // nAddress.address_title = rAddress.address_title;130 // nAddress.address_line1 = rAddress.address_line1;131 // nAddress.address_line2 = rAddress.address_line2;132 // nAddress.location = rAddress.location;133 // nAddress.postal_code = rAddress.postal_code;134 // nAddress.city = rAddress.city;135 // nAddress.state = rAddress.state;136 // nAddress.country = rAddress.country;137 // nAddress.email = rAddress.email;138 // nAddress.phone = rAddress.phone;139 // nAddress.fax = rAddress.fax;140141 // update Address142 // try {143 // await nAddress.save();144145 // const fAddress = await Address.findOne(rAddress.address_id);146 // console.log('fAddress by Id after save: ', fAddress);147 // return fAddress;148 // } catch (error) {149 // this.logger.error(150 // `!> Failed to update address: ${JSON.stringify(rAddress)} ;`,151 // error.stack,152 // );153 // throw new InternalServerErrorException({154 // message: '!> Failed to update address',155 // origin: '@address.repository.ts',156 // address: rAddress,157 // error: error.stack,158 // });159 // }160161 }162163}164165// export class AddressRepositoryFake {166// public async build(): Promise<void> {}167// public async rebuild(): Promise<void> {}168// public async fetchById(): Promise<void> {}
...
Using AI Code Generation
1var strykerParent = require('stryker-parent');2var address = strykerParent.address;3console.log(address);4var strykerParent = require('stryker-parent');5var address = strykerParent.address;6console.log(address);7var strykerParent = require('stryker-parent');8var address = strykerParent.address;9console.log(address);10var strykerParent = require('stryker-parent');11var address = strykerParent.address;12console.log(address);13var strykerParent = require('stryker-parent');14var address = strykerParent.address;15console.log(address);16var strykerParent = require('stryker-parent');17var address = strykerParent.address;18console.log(address);19var strykerParent = require('stryker-parent');20var address = strykerParent.address;21console.log(address);22var strykerParent = require('stryker-parent');23var address = strykerParent.address;24console.log(address);25var strykerParent = require('stryker-parent');26var address = strykerParent.address;27console.log(address);28var strykerParent = require('stryker-parent');29var address = strykerParent.address;30console.log(address);31var strykerParent = require('stryker-parent');32var address = strykerParent.address;33console.log(address);34var strykerParent = require('stryker-parent');35var address = strykerParent.address;36console.log(address);37var strykerParent = require('stryker-parent');
Using AI Code Generation
1const strykerParent = require('stryker-parent');2const address = strykerParent.address;3const address2 = strykerParent.address2;4const strykerParent2 = require('stryker-parent2');5const address3 = strykerParent2.address;6const address4 = strykerParent2.address2;7const strykerParent3 = require('stryker-parent3');8const address5 = strykerParent3.address;9const address6 = strykerParent3.address2;10const strykerParent4 = require('stryker-parent4');11const address7 = strykerParent4.address;12const address8 = strykerParent4.address2;13const strykerParent5 = require('stryker-parent5');14const address9 = strykerParent5.address;15const address10 = strykerParent5.address2;16const strykerParent6 = require('stryker-parent6');17const address11 = strykerParent6.address;18const address12 = strykerParent6.address2;19const strykerParent7 = require('stryker-parent7');20const address13 = strykerParent7.address;21const address14 = strykerParent7.address2;22const strykerParent8 = require('stryker-parent8');23const address15 = strykerParent8.address;24const address16 = strykerParent8.address2;25const strykerParent9 = require('stryker-parent9');26const address17 = strykerParent9.address;27const address18 = strykerParent9.address2;28const strykerParent10 = require('stryker-parent10');29const address19 = strykerParent10.address;30const address20 = strykerParent10.address2;
Using AI Code Generation
1var address = require('stryker-parent').address;2address('123 Main Street', 'San Francisco', 'CA', '94105');3var address = require('stryker-parent').address;4var address = require('stryker-parent').address;5address('123 Main Street', 'San Francisco', 'CA', '94105');6var address = require('stryker-parent').address;7var address = require('stryker-parent').address;8var address = require('stryker-parent').address;9address('123 Main Street', 'San Francisco', 'CA', '94105');10var address = require('stryker-pare
Using AI Code Generation
1var stryker = require('stryker-parent');2var address = stryker.address;3var address = new address();4address.getaddress();5var stryker = require('stryker-parent');6var address = stryker.address;7var address = new address();8address.getaddress();9var stryker = require('stryker-parent');10var address = stryker.address;11var address = new address();12address.getaddress();13var stryker = require('stryker-parent');14var address = stryker.address;15var address = new address();16address.getaddress();17var stryker = require('stryker-parent');18var address = stryker.address;19var address = new address();20address.getaddress();21var stryker = require('stryker-parent');22var address = stryker.address;23var address = new address();24address.getaddress();25var stryker = require('stryker-parent');26var address = stryker.address;27var address = new address();28address.getaddress();29var stryker = require('stryker-parent');30var address = stryker.address;31var address = new address();32address.getaddress();33var stryker = require('stryker-parent');34var address = stryker.address;35var address = new address();36address.getaddress();37var stryker = require('stryker-parent');38var address = stryker.address;39var address = new address();40address.getaddress();41var stryker = require('stryker-parent');
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!!