expand datastore CLI tests to include creating users and accounts in which to store data

This commit is contained in:
Jude Nelson
2016-12-21 19:03:53 -05:00
parent b7948c7d6f
commit fe928b99a5

View File

@@ -29,6 +29,7 @@ import blockstack_client
import blockstack_profiles
import blockstack_gpg
import sys
import errno
wallets = [
testlib.Wallet( "5JesPiN68qt44Hc2nT8qmyZ1JDwHebfoh9KQ52Lazb1m1LaKNj9", 100000000000 ),
@@ -45,6 +46,7 @@ wallets = [
consensus = "17ac43c1d8549c3181b200f1bf97eb7d"
wallet_keys = None
error = False
index_file_data = "<html><head></head><body>foo.test hello world</body></html>"
def scenario( wallets, **kw ):
@@ -86,30 +88,106 @@ def scenario( wallets, **kw ):
testlib.next_block( **kw )
# make a datastore
res = testlib.blockstack_cli_advanced_put_datastore( "foo.test", "foo_datastore", drivers=['disk'], password="0123456789abcdef" )
# make an index file
index_file_path = "/tmp/name_preorder_register_update_app_publish.foo.test.index.html"
with open(index_file_path, "w") as f:
f.write(index_file_data)
# make an application
res = testlib.blockstack_cli_app_publish("foo.test", "get_mutable,put_mutable,delete_mutable", index_file_path, appname="bar", drivers="disk", password="0123456789abcdef" )
if 'error' in res:
print 'failed to create datastore: {}'.format(res['error'])
print "failed to create foo.test/bar"
print json.dumps(res, indent=4, sort_keys=True)
return False
# get the datastore (for fun)
dsres = testlib.blockstack_cli_advanced_get_datastore( "foo.test", "foo_datastore", password='0123456789abcdef' )
# make a user
res = testlib.blockstack_cli_create_user( "foo_id", password="0123456789abcdef" )
if 'error' in res:
print 'failed to get datastore: {}'.format(res['error'])
print 'failed to create user foo_id'
print json.dumps(res, indent=4, sort_keys=True)
return False
# delete the user
res = testlib.blockstack_cli_delete_user( "foo_id", password="0123456789abcdef" )
if 'error' in res:
print 'failed to delete user foo_id'
print json.dumps(res, indent=4, sort_keys=True)
return False
# get the user (should fail)
res = testlib.blockstack_cli_get_user( "foo_id" )
if 'error' not in res:
print 'accidentally got foo_id'
print json.dumps(res, indent=4, sort_keys=True)
return False
# list the user (should be empty)
res = testlib.blockstack_cli_list_users()
if len(res) > 0:
print 'accidentally got multiple users'
print json.dumps(res, indent=4, sort_keys=True)
return False
# make a user (again)
res = testlib.blockstack_cli_create_user( "foo_id", password="0123456789abcdef" )
if 'error' in res:
print 'failed to create user foo_id'
print json.dumps(res, indent=4, sort_keys=True)
return False
# make an app user account
res = testlib.blockstack_cli_app_put_account( "foo_id", "foo.test", "bar", "get_mutable", session_lifetime=3600 )
if 'error' in res:
print "failed to create account for foo_id in foo.test/bar"
print json.dumps(res, indent=4, sort_keys=True)
return False
# get the user account
res = testlib.blockstack_cli_app_get_account( 'foo_id', "foo.test", "bar" )
if 'error' in res:
print 'failed to get user foo_id'
print json.dumps(res, indent=4, sort_keys=True)
return False
# list users
res = testlib.blockstack_cli_list_users()
if 'error' in res:
print 'failed to list users'
print json.dumps(res, indent=4, sort_keys=True)
return False
if len(res) != 1:
print "invalid user list: {}".format(res)
return False
if res[0]['user_id'] != 'foo_id':
print "invalid user list: {}".format(res)
return False
# make directories
for dpath in ['/dir1', '/dir2', '/dir1/dir3', '/dir1/dir3/dir4']:
print 'mkdir {}'.format(dpath)
res = testlib.blockstack_cli_advanced_datastore_mkdir( 'foo.test', 'foo_datastore', dpath )
res = testlib.blockstack_cli_datastore_mkdir( 'foo_id', "foo.test", "bar", dpath )
if 'error' in res:
print 'failed to mkdir {}: {}'.format(dpath, res['error'])
return False
# stat directories
for dpath in ['/dir1', '/dir2', '/dir1/dir3', '/dir1/dir3/dir4']:
print 'stat {}'.format(dpath)
res = testlib.blockstack_cli_datastore_stat( 'foo_id', "foo.test", "bar", dpath )
if 'error' in res:
print 'failed to stat {}: {}'.format(dpath, res['error'])
return False
if res['inode']['type'] != blockstack_client.schemas.MUTABLE_DATUM_DIR_TYPE:
print 'not a directory: {}, {}'.format(dpath, res)
return False
# list directories
for dpath, expected in [('/', ['dir1', 'dir2']), ('/dir1', ['dir3']), ('/dir1/dir3', ['dir4']), ('/dir1/dir3/dir4', [])]:
print 'listdir {}'.format(dpath)
res = testlib.blockstack_cli_advanced_datastore_listdir( 'foo.test', 'foo_datastore', dpath )
res = testlib.blockstack_cli_datastore_listdir( 'foo_id', "foo.test", "bar", dpath )
if 'error' in res:
print 'failed to listdir {}: {}'.format(dpath, res['error'])
return False
@@ -128,15 +206,27 @@ def scenario( wallets, **kw ):
for dpath in ['/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4', '/dir1/dir3/dir4/file5']:
print 'putfile {}'.format(dpath)
data = 'hello {}'.format(os.path.basename(dpath))
res = testlib.blockstack_cli_advanced_datastore_putfile( 'foo.test', 'foo_datastore', dpath, data )
res = testlib.blockstack_cli_datastore_putfile( 'foo_id', "foo.test", "bar", dpath, data )
if 'error' in res:
print 'failed to putfile {}: {}'.format(dpath, res['error'])
return False
# stat files
for dpath in ['/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4', '/dir1/dir3/dir4/file5']:
print 'stat {}'.format(dpath)
res = testlib.blockstack_cli_datastore_stat( 'foo_id', "foo.test", "bar", dpath )
if 'error' in res:
print 'failed to stat {}: {}'.format(dpath, res['error'])
return False
if res['inode']['type'] != blockstack_client.schemas.MUTABLE_DATUM_FILE_TYPE:
print 'not a file: {}, {}'.format(dpath, res)
return False
# list directories again
for dpath, expected in [('/', ['dir1', 'dir2', 'file1', 'file2']), ('/dir1', ['dir3', 'file3']), ('/dir1/dir3', ['dir4', 'file4']), ('/dir1/dir3/dir4', ['file5'])]:
print 'listdir {}'.format(dpath)
res = testlib.blockstack_cli_advanced_datastore_listdir( 'foo.test', 'foo_datastore', dpath )
res = testlib.blockstack_cli_datastore_listdir( 'foo_id', "foo.test", "bar", dpath )
if 'error' in res:
print 'failed to listdir {}: {}'.format(dpath, res['error'])
return False
@@ -154,7 +244,7 @@ def scenario( wallets, **kw ):
# get files
for dpath in ['/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4', '/dir1/dir3/dir4/file5']:
print 'getfile {}'.format(dpath)
res = testlib.blockstack_cli_advanced_datastore_getfile( 'foo.test', 'foo_datastore', dpath )
res = testlib.blockstack_cli_datastore_getfile( 'foo_id', "foo.test", "bar", dpath )
if 'error' in res:
print 'failed to getfile {}: {}'.format(dpath, res['error'])
return False
@@ -167,15 +257,39 @@ def scenario( wallets, **kw ):
# remove files
for dpath in ['/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4', '/dir1/dir3/dir4/file5']:
print 'deletefile {}'.format(dpath)
res = testlib.blockstack_cli_advanced_datastore_deletefile( 'foo.test', 'foo_datastore', dpath )
res = testlib.blockstack_cli_datastore_deletefile( 'foo_id', "foo.test", "bar", dpath )
if 'error' in res:
print 'failed to deletefile {}: {}'.format(dpath, res['error'])
return False
# stat files (should all fail)
for dpath in ['/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4', '/dir1/dir3/dir4/file5']:
print 'stat {} (expect failure)'.format(dpath)
res = testlib.blockstack_cli_datastore_stat( 'foo_id', "foo.test", "bar", dpath )
if 'error' not in res or 'errno' not in res:
print 'accidentally succeeded to stat {}: {}'.format(dpath, res)
return False
if res['errno'] != errno.ENOENT:
print 'wrong errno: {}'.format(res)
return False
# get files (should all fail)
for dpath in ['/file1', '/file2', '/dir1/file3', '/dir1/dir3/file4', '/dir1/dir3/dir4/file5']:
print 'getfile {} (expect failure)'.format(dpath)
res = testlib.blockstack_cli_datastore_getfile( 'foo_id', "foo.test", "bar", dpath )
if 'error' not in res or 'errno' not in res:
print 'accidentally succeeded to get {}: {}'.format(dpath, res)
return False
if res['errno'] != errno.ENOENT:
print 'wrong errno: {}'.format(res)
return False
# list directories, 3rd time
for dpath, expected in [('/', ['dir1', 'dir2']), ('/dir1', ['dir3']), ('/dir1/dir3', ['dir4']), ('/dir1/dir3/dir4', [])]:
print 'listdir {}'.format(dpath)
res = testlib.blockstack_cli_advanced_datastore_listdir( 'foo.test', 'foo_datastore', dpath )
res = testlib.blockstack_cli_datastore_listdir( 'foo_id', "foo.test", "bar", dpath )
if 'error' in res:
print 'failed to listdir {}: {}'.format(dpath, res['error'])
return False
@@ -193,14 +307,38 @@ def scenario( wallets, **kw ):
# remove directories
for dpath in ['/dir1/dir3/dir4', '/dir1/dir3', '/dir2', '/dir1']:
print 'rmdir {}'.format(dpath)
res = testlib.blockstack_cli_advanced_datastore_rmdir( 'foo.test', 'foo_datastore', dpath )
res = testlib.blockstack_cli_datastore_rmdir( 'foo_id', "foo.test", "bar", dpath )
if 'error' in res:
print 'failed to rmdir {}: {}'.format(dpath, res['error'])
return False
# stat directories (should all fail)
for dpath in ['/dir1/dir3/dir4', '/dir1/dir3', '/dir2', '/dir1']:
print 'stat {} (expect failure)'.format(dpath)
res = testlib.blockstack_cli_datastore_stat( 'foo_id', "foo.test", "bar", dpath )
if 'error' not in res or 'errno' not in res:
print 'accidentally succeeded to stat {}: {}'.format(dpath, res)
return False
if res['errno'] != errno.ENOENT:
print 'wrong errno: {}'.format(res)
return False
# list directories (should all fail)
for dpath, expected in [('/dir1', ['dir3']), ('/dir1/dir3', ['dir4']), ('/dir1/dir3/dir4', [])]:
print 'listdir {} (expect failure)'.format(dpath)
res = testlib.blockstack_cli_datastore_listdir( 'foo_id', "foo.test", "bar", dpath )
if 'error' not in res or 'errno' not in res:
print 'accidentally succeeded to list {}: {}'.format(dpath, res)
return False
if res['errno'] != errno.ENOENT:
print 'wrong errno: {}'.format(res)
return False
# root should be empty
print 'listdir {}'.format('/')
res = testlib.blockstack_cli_advanced_datastore_listdir( 'foo.test', 'foo_datastore', '/' )
res = testlib.blockstack_cli_datastore_listdir( 'foo_id', "foo.test", "bar", '/' )
if 'error' in res:
print 'failed to listdir /: {}'.format(res['error'])
return False
@@ -210,16 +348,44 @@ def scenario( wallets, **kw ):
print 'root still has children: {}'.format(res['idata'].keys())
return False
# delete datastore (shouldn't have to force)
res = testlib.blockstack_cli_advanced_delete_datastore( 'foo.test', 'foo_datastore', password="0123456789abcdef")
# delete account
res = testlib.blockstack_cli_app_delete_account( 'foo_id', "foo.test", "bar", password="0123456789abcdef" )
if 'error' in res:
print 'failed to delete datastore: {}'.format(res['error'])
print 'failed to delete foo_id'
print json.dumps(res, indent=4, sort_keys=True)
return False
# get the account (should fail)
res = testlib.blockstack_cli_app_get_account( 'foo_id', "foo.test", "bar" )
if 'error' not in res:
print 'accidentally got user foo_id'
print json.dumps(res, indent=4, sort_keys=True)
return False
# delete the user
res = testlib.blockstack_cli_delete_user( "foo_id", password="0123456789abcdef" )
if 'error' in res:
print 'failed to delete user foo_id'
print json.dumps(res, indent=4, sort_keys=True)
return False
# get the user (should fail)
res = testlib.blockstack_cli_get_user( "foo_id" )
if 'error' not in res:
print 'accidentally got foo_id'
print json.dumps(res, indent=4, sort_keys=True)
return False
# list the user (should be empty)
res = testlib.blockstack_cli_list_users()
if len(res) > 0:
print 'accidentally got multiple users'
print json.dumps(res, indent=4, sort_keys=True)
return False
testlib.next_block( **kw )
def check( state_engine ):
global wallet_keys, error