def scenario(wallets, **kw): print '\nactivating segwit\n' virtualchain.set_features("segwit", True) print '\nsegwit state: {}\n'.format(virtualchain.get_features('segwit')) # make a test namespace resp = testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) if debug or 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) if debug or 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.blockstack_name_import("foo.test", wallets[9].addr, "11" * 20, wallets[1].privkey) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.blockstack_namespace_ready("test", wallets[1].privkey) if debug or 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.blockstack_name_update("foo.test", "22" * 20, wallets[9].privkey) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw) resp = testlib.blockstack_name_transfer("foo.test", wallets[10].addr, True, wallets[9].privkey) if 'error' in resp: print json.dumps(resp, indent=4) testlib.next_block(**kw)
def scenario(wallets, **kw): print '\nactivating segwit\n' virtualchain.set_features("segwit", True) print '\nsegwit state: {}\n'.format(virtualchain.get_features('segwit')) testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[0].privkey) virtualchain.set_features("segwit", False) testlib.next_block(**kw) virtualchain.set_features("segwit", True) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey) virtualchain.set_features("segwit", False) testlib.next_block(**kw) virtualchain.set_features("segwit", True) testlib.blockstack_namespace_ready("test", wallets[1].privkey) virtualchain.set_features("segwit", False) testlib.next_block(**kw) virtualchain.set_features("segwit", True) testlib.blockstack_name_preorder("foo.test", wallets[2].privkey, wallets[3].addr, wallet=wallets[3]) virtualchain.set_features("segwit", False) testlib.next_block(**kw) virtualchain.set_features("segwit", True) testlib.blockstack_name_register("foo.test", wallets[2].privkey, wallets[3].addr, wallet=wallets[3]) virtualchain.set_features("segwit", False) testlib.next_block(**kw) virtualchain.set_features("segwit", True)
def scenario(wallets, **kw): print '\nactivating segwit\n' virtualchain.set_features("segwit", True) print '\nsegwit state: {}\n'.format(virtualchain.get_features('segwit')) testlib.blockstack_namespace_preorder("test", wallets[1].addr, wallets[5].privkey) testlib.blockstack_namespace_preorder("mult", wallets[2].addr, wallets[0].privkey) testlib.next_block(**kw) testlib.blockstack_namespace_reveal( "test", wallets[1].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[5].privkey) testlib.blockstack_namespace_reveal( "mult", wallets[2].addr, 52595, 250, 4, [6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10, 10, wallets[0].privkey, version_bits=2) testlib.next_block(**kw) private_keychain = keychain.PrivateKeychain.from_private_key( wallets[2].privkey) private_keys = [ wallets[2].privkey ] # NOTE: always start with the reveal key, then use children for i in xrange(0, 4): import_key = private_keychain.child(i).private_key() print "fund {} (child {})".format(import_key, i) res = testlib.send_funds( wallets[1].privkey, 100000000, virtualchain.BitcoinPrivateKey(import_key).public_key().address()) if 'error' in res: print json.dumps(res, indent=4, sort_keys=True) return False testlib.next_block(**kw) private_keys.append(import_key) # should succeed resp = testlib.blockstack_name_import("foo.mult", wallets[2].addr, '00' * 20, private_keys[0]) if 'error' in resp: print json.dumps(resp, indent=4, sort_keys=True) return False testlib.next_block(**kw) # should succeed resp = testlib.blockstack_name_import("bar.mult", wallets[3].addr, "11" * 20, private_keys[1]) if 'error' in resp: print json.dumps(resp, indent=4, sort_keys=True) return False # should succeed resp = testlib.blockstack_name_import("baz.mult", wallets[4].addr, "22" * 20, private_keys[2]) if 'error' in resp: print json.dumps(resp, indent=4, sort_keys=True) return False # should succeed resp = testlib.blockstack_name_import("goo.mult", wallets[5].addr, "33" * 20, private_keys[3]) if 'error' in resp: print json.dumps(resp, indent=4, sort_keys=True) return False testlib.next_block(**kw) testlib.blockstack_namespace_ready("test", wallets[1].privkey) testlib.blockstack_namespace_ready("mult", wallets[2].privkey) testlib.next_block(**kw) namespace_balance = testlib.get_balance(wallets[0].addr) # get prices hello_cost = testlib.blockstack_get_name_cost('hello.mult') world_cost = testlib.blockstack_get_name_cost('world.mult') foo_cost = testlib.blockstack_get_name_cost('foo.mult') # register/renew res = testlib.blockstack_name_preorder("hello.mult", wallets[1].privkey, wallets[2].addr) if 'error' in res: print res return False res = testlib.blockstack_name_preorder('world.mult', wallets[6].privkey, wallets[7].addr, wallet=wallets[7]) if 'error' in res: print res return False res = testlib.blockstack_name_renew('foo.mult', wallets[2].privkey) if 'error' in res: print res return False testlib.next_block(**kw) new_namespace_balance = testlib.get_balance(wallets[0].addr) if new_namespace_balance != namespace_balance + hello_cost + world_cost + foo_cost: print 'wrong balance' print new_namespace_balance print namespace_balance print hello_cost print foo_cost return False res = testlib.blockstack_name_register("hello.mult", wallets[1].privkey, wallets[2].addr) if 'error' in res: print res return False res = testlib.blockstack_name_register('world.mult', wallets[6].privkey, wallets[7].addr, wallet=wallets[7], zonefile_hash='44' * 20) if 'error' in res: print res return False testlib.next_block(**kw)
def make_wallet(password, payment_privkey_info=None, owner_privkey_info=None, data_privkey_info=None, test_legacy=False, encrypt=True, segwit=None): """ Make a new, encrypted wallet structure. The owner and payment keys will be 2-of-3 multisig key bundles. The data keypair will be a single-key bundle. Return the new wallet on success. Return {'error': ...} on failure """ if test_legacy and not BLOCKSTACK_TEST: raise Exception("Not in testing but tried to make a legacy wallet") if segwit is None: # no preference given. # safe to use by default post-F-day 2017 (Dec 1 2017) if time.time() >= 1512086400: segwit = True else: # defer to virtualchain segwit = virtualchain.get_features('segwit') # default to 2-of-3 multisig key info if data isn't given if segwit: payment_privkey_info = virtualchain.make_multisig_segwit_wallet( 2, 3 ) if payment_privkey_info is None and not test_legacy else payment_privkey_info owner_privkey_info = virtualchain.make_multisig_segwit_wallet( 2, 3 ) if owner_privkey_info is None and not test_legacy else owner_privkey_info else: payment_privkey_info = virtualchain.make_multisig_wallet( 2, 3 ) if payment_privkey_info is None and not test_legacy else payment_privkey_info owner_privkey_info = virtualchain.make_multisig_wallet( 2, 3 ) if owner_privkey_info is None and not test_legacy else owner_privkey_info data_privkey_info = ecdsa_private_key().to_hex( ) if data_privkey_info is None and not test_legacy else data_privkey_info decrypted_wallet = { 'owner_addresses': [virtualchain.get_privkey_address(owner_privkey_info)], 'owner_privkey': owner_privkey_info, 'payment_addresses': [virtualchain.get_privkey_address(payment_privkey_info)], 'payment_privkey': payment_privkey_info, 'data_pubkey': ecdsa_private_key(data_privkey_info).public_key().to_hex(), 'data_pubkeys': [ecdsa_private_key(data_privkey_info).public_key().to_hex()], 'data_privkey': data_privkey_info, 'version': SERIES_VERSION, } if not test_legacy: jsonschema.validate(decrypted_wallet, WALLET_SCHEMA_CURRENT) if encrypt: encrypted_wallet = encrypt_wallet(decrypted_wallet, password, test_legacy=test_legacy) if 'error' in encrypted_wallet: return encrypted_wallet # sanity check try: jsonschema.validate(encrypted_wallet, ENCRYPTED_WALLET_SCHEMA_CURRENT) except ValidationError as ve: if test_legacy: # no data key is permitted assert BLOCKSTACK_TEST jsonschema.validate(encrypted_wallet, ENCRYPTED_WALLET_SCHEMA_CURRENT_NODATAKEY) else: raise return encrypted_wallet else: return decrypted_wallet