Ejemplo n.º 1
0
def test(testfilter):
    global datadir1
    global datadir2
    
    _lib.StartTestGroup("Run node with 30 blocks and test import from second node")
    
    _lib.CleanTestFolders()
    
    inf = blocksnodes.MakeBlockchainWithBlocks('30000')
    datadir = inf[0]
    address1 = inf[1]
    address1_2 = inf[2]
    address1_3 = inf[3]
    
    for x in range(5, 31):
        _lib.StartTestGroup("Create block #"+str(x))
        for y in range(0, x-1):
            tx=_transfers.Send(datadir,address1,address1_2,0.001)
        
        txlist = transactions.GetUnapprovedTransactions(datadir)
        _lib.FatalAssert(len(txlist) == x-1,"Should be "+str(x-1)+" unapproved transaction")
        
        blockchash = _blocks.MintBlock(datadir,address1)
        blocks = _blocks.WaitBlocks(datadir, x)
        _lib.FatalAssert(len(blocks) == x,"Should be "+str(x)+" blocks on server 1")
    
    
    #_node.StartNodeInteractive(datadir, address1,'30000', "Server 1")
    startnode.StartNode(datadir, address1,'30000', "Server 1")
    datadir1 = datadir
    managenodes.RemoveAllNodes(datadir1)
    
    d = pullsync.StartNodeAndImport('30001', '30000', "Server 2", 0, "_2_", "xxx.com" )
    datadir2 = d[0]
    address2 = d[1]
    
    blocks = _blocks.GetBlocks(datadir2)
    
    # wait when all 30 bocks are on node 2
    blocks = _blocks.WaitBlocks(datadir2, 30, 100)# 100 sec
    
    _lib.FatalAssert(len(blocks) == 30,"Should be 17 blocks on server 2")
    
    startnode.StopNode(datadir1,"Server 1")
    datadir1 = ""
    
    time.sleep(4)# allow to complete blocks adding
    startnode.StopNode(datadir2,"Server 2")
    datadir2 = ""
    
    #_lib.RemoveTestFolder(datadir)
    _lib.EndTestGroupSuccess()
Ejemplo n.º 2
0
def test(testfilter):
    _lib.StartTestGroup("Blocks making")

    _lib.CleanTestFolders()
    datadir = _lib.CreateTestFolder()

    r = PrepareBlockchain(datadir, '30000')
    address = r[0]

    # create another 3 addresses
    address2 = transactions.CreateWallet(datadir)
    address3 = transactions.CreateWallet(datadir)

    _lib.StartTestGroup("Do transactions")

    transactions.GetUnapprovedTransactionsEmpty(datadir)

    amount1 = '1'
    amount2 = '2'
    amount3 = '3'

    txid1 = _transfers.Send(datadir, address, address2, amount1)

    txlist = transactions.GetUnapprovedTransactions(datadir)

    _lib.FatalAssert(len(txlist) == 1, "Should be 1 unapproved transaction")

    time.sleep(1)
    txid2 = _transfers.Send(datadir, address, address3, amount2)

    txlist = transactions.GetUnapprovedTransactions(datadir)

    _lib.FatalAssert(len(txlist) == 2, "Should be 2 unapproved transaction")

    time.sleep(1)
    txid3 = _transfers.Send(datadir, address, address3, amount3)

    # node needs some time to make a block, so transaction still will be in list of unapproved
    txlist = transactions.GetUnapprovedTransactions(datadir)

    _lib.FatalAssert(len(txlist) == 3, "Should be 3 unapproved transaction")

    time.sleep(1)
    txid4 = _transfers.Send(datadir, address3, address2, amount1)

    # node needs some time to make a block, so transaction still will be in list of unapproved
    txlist = transactions.GetUnapprovedTransactions(datadir)

    _lib.FatalAssert(len(txlist) == 4, "Should be 4 unapproved transaction")

    if txid1 not in txlist.keys():
        _lib.Fatal("Transaction 1 is not in the list of transactions")

    if txid2 not in txlist.keys():
        _lib.Fatal("Transaction 2 is not in the list of transactions")

    if txid3 not in txlist.keys():
        _lib.Fatal("Transaction 3 is not in the list of transactions")

    if txid4 not in txlist.keys():
        _lib.Fatal("Transaction 4 is not in the list of transactions")

    _lib.FatalAssertFloat(amount1, txlist[txid1][2],
                          "Amount of transaction 1 is wrong")

    _lib.FatalAssertFloat(amount2, txlist[txid2][2],
                          "Amount of transaction 2 is wrong")

    _lib.FatalAssertFloat(amount3, txlist[txid3][2],
                          "Amount of transaction 3 is wrong")

    _lib.FatalAssertFloat(amount1, txlist[txid4][2],
                          "Amount of transaction 4 is wrong")

    blockchash = _blocks.MintBlock(datadir, address)

    transactions.GetUnapprovedTransactionsEmpty(datadir)

    blockshashes = _blocks.GetBlocks(datadir)

    _lib.FatalAssert(
        len(blockshashes) == 2, "Should be 2 blocks in blockchain")

    _lib.StartTestGroup("Send 30 transactions")

    microamount = 0.01
    # send many transactions
    for i in range(1, 10):
        _lib.StartTest("Iteration " + str(i))
        txid1 = _transfers.Send(datadir, address, address2, microamount)
        txid2 = _transfers.Send(datadir, address2, address3, microamount)
        txid3 = _transfers.Send(datadir, address3, address, microamount)

        txlist = transactions.GetUnapprovedTransactions(datadir)

        _lib.FatalAssert(
            len(txlist) == i * 3,
            "Should be " + str(i * 3) + " unapproved transaction")

        if txid1 not in txlist.keys():
            _lib.Fatal(
                "Transaction 1 is not in the list of transactions after iteration "
                + str(i))

        if txid2 not in txlist.keys():
            _lib.Fatal(
                "Transaction 2 is not in the list of transactions after iteration "
                + str(i))

        if txid3 not in txlist.keys():
            _lib.Fatal(
                "Transaction 3 is not in the list of transactions after iteration "
                + str(i))

        time.sleep(1)

    blockchash = _blocks.MintBlock(datadir, address)
    transactions.GetUnapprovedTransactionsEmpty(datadir)

    blockshashes = _blocks.GetBlocks(datadir)

    _lib.FatalAssert(
        len(blockshashes) == 3, "Should be 3 blocks in blockchain")

    _lib.StartTestGroup("Send 30 transactions. Random value")

    microamountmax = 0.01
    microamountmin = 0.0095
    # send many transactions
    for i in range(1, 11):
        _lib.StartTest("Iteration " + str(i))
        a1 = random.uniform(microamountmin, microamountmax)
        a2 = random.uniform(microamountmin, microamountmax)
        a3 = random.uniform(microamountmin, microamountmax)
        txid1 = _transfers.Send(datadir, address, address2, a1)
        txid2 = _transfers.Send(datadir, address2, address3, a2)
        txid3 = _transfers.Send(datadir, address3, address, a3)

        txlist = transactions.GetUnapprovedTransactions(datadir)

        _lib.FatalAssert(
            len(txlist) == i * 3,
            "Should be " + str(i * 3) + " unapproved transaction")

        if txid1 not in txlist.keys():
            _lib.Fatal(
                "Transaction 1 is not in the list of transactions after iteration "
                + str(i))

        if txid2 not in txlist.keys():
            _lib.Fatal(
                "Transaction 2 is not in the list of transactions after iteration "
                + str(i))

        if txid3 not in txlist.keys():
            _lib.Fatal(
                "Transaction 3 is not in the list of transactions after iteration "
                + str(i))

        time.sleep(1)

    blockchash = _blocks.MintBlock(datadir, address)
    transactions.GetUnapprovedTransactionsEmpty(datadir)

    blockshashes = _blocks.GetBlocks(datadir)

    _lib.FatalAssert(
        len(blockshashes) == 4, "Should be 4 blocks in blockchain")

    #_lib.RemoveTestFolder(datadir)
    _lib.EndTestGroupSuccess()
Ejemplo n.º 3
0
def MakeBlockchainWithBlocks(port):

    datadir = _lib.CreateTestFolder()

    r = blocksbasic.PrepareBlockchain(datadir, port)
    address = r[0]

    # create another 3 addresses
    address2 = transactions.CreateWallet(datadir)
    address3 = transactions.CreateWallet(datadir)

    _lib.StartTestGroup("Do _transfers")

    transactions.GetUnapprovedTransactionsEmpty(datadir)

    amount1 = '1'
    amount2 = '2'
    amount3 = '3'

    txid1 = _transfers.Send(datadir, address, address2, amount1)
    txlist = transactions.GetUnapprovedTransactions(datadir)
    _lib.FatalAssert(len(txlist) == 1, "Should be 1 unapproved transaction")

    txid2 = _transfers.Send(datadir, address, address3, amount2)

    txlist = transactions.GetUnapprovedTransactions(datadir)
    _lib.FatalAssert(len(txlist) == 2, "Should be 2 unapproved transaction")
    txid3 = _transfers.Send(datadir, address, address3, amount3)

    # node needs some time to make a block, so transaction still will be in list of unapproved
    txlist = transactions.GetUnapprovedTransactions(datadir)

    _lib.FatalAssert(len(txlist) == 3, "Should be 3 unapproved transaction")

    txid4 = _transfers.Send(datadir, address3, address2, amount1)

    # node needs some time to make a block, so transaction still will be in list of unapproved
    txlist = transactions.GetUnapprovedTransactions(datadir)

    _lib.FatalAssert(len(txlist) == 4, "Should be 4 unapproved transaction")

    if txid1 not in txlist.keys():
        _lib.Fatal("Transaction 1 is not in the list of transactions")

    if txid2 not in txlist.keys():
        _lib.Fatal("Transaction 2 is not in the list of transactions")

    if txid3 not in txlist.keys():
        _lib.Fatal("Transaction 3 is not in the list of transactions")

    if txid4 not in txlist.keys():
        _lib.Fatal("Transaction 4 is not in the list of transactions")

    _lib.FatalAssertFloat(amount1, txlist[txid1][3],
                          "Amount of transaction 1 is wrong")

    _lib.FatalAssertFloat(amount2, txlist[txid2][3],
                          "Amount of transaction 2 is wrong")

    _lib.FatalAssertFloat(amount3, txlist[txid3][3],
                          "Amount of transaction 3 is wrong")

    _lib.FatalAssertFloat(amount1, txlist[txid4][3],
                          "Amount of transaction 4 is wrong")

    blockchash = _blocks.MintBlock(datadir, address)

    transactions.GetUnapprovedTransactionsEmpty(datadir)

    blockshashes = _blocks.GetBlocks(datadir)

    _lib.FatalAssert(
        len(blockshashes) == 2, "Should be 2 blocks in blockchain")

    _lib.StartTestGroup("Send 3 transactions")

    microamount = 0.01

    txid1 = _transfers.Send(datadir, address, address2, microamount)
    txid2 = _transfers.Send(datadir, address2, address3, microamount)
    txid3 = _transfers.Send(datadir, address3, address, microamount)

    txlist = transactions.GetUnapprovedTransactions(datadir)

    _lib.FatalAssert(len(txlist) == 3, "Should be 3 unapproved transaction")

    if txid1 not in txlist.keys():
        _lib.Fatal(
            "Transaction 1 is not in the list of transactions after iteration "
            + str(i))

    if txid2 not in txlist.keys():
        _lib.Fatal(
            "Transaction 2 is not in the list of transactions after iteration "
            + str(i))

    if txid3 not in txlist.keys():
        _lib.Fatal(
            "Transaction 3 is not in the list of transactions after iteration "
            + str(i))

    blockchash = _blocks.MintBlock(datadir, address)
    transactions.GetUnapprovedTransactionsEmpty(datadir)

    blockshashes = _blocks.GetBlocks(datadir)

    _lib.FatalAssert(
        len(blockshashes) == 3, "Should be 3 blocks in blockchain")

    _lib.StartTestGroup("Send 3 transactions. Random value")

    microamountmax = 0.01
    microamountmin = 0.0095

    a1 = round(random.uniform(microamountmin, microamountmax), 8)
    a2 = round(random.uniform(microamountmin, microamountmax), 8)
    a3 = round(random.uniform(microamountmin, microamountmax), 8)
    txid1 = _transfers.Send(datadir, address, address2, a1)
    txid2 = _transfers.Send(datadir, address2, address3, a2)
    txid3 = _transfers.Send(datadir, address3, address, a3)

    txlist = transactions.GetUnapprovedTransactions(datadir)

    _lib.FatalAssert(len(txlist) == 3, "Should be 3 unapproved transaction")

    if txid1 not in txlist.keys():
        _lib.Fatal(
            "Transaction 1 is not in the list of transactions after iteration "
            + str(i))

    if txid2 not in txlist.keys():
        _lib.Fatal(
            "Transaction 2 is not in the list of transactions after iteration "
            + str(i))

    if txid3 not in txlist.keys():
        _lib.Fatal(
            "Transaction 3 is not in the list of transactions after iteration "
            + str(i))

    blockchash = _blocks.MintBlock(datadir, address)
    transactions.GetUnapprovedTransactionsEmpty(datadir)

    blockshashes = _blocks.GetBlocks(datadir)

    _lib.FatalAssert(
        len(blockshashes) == 4, "Should be 4 blocks in blockchain")

    return [datadir, address, address2, address3]
Ejemplo n.º 4
0
def test(testfilter):

    
    _lib.StartTestGroup("SQL basic")

    _lib.CleanTestFolders()
    datadir = _lib.CreateTestFolder()

    address = startnode.InitBockchain(datadir)
    
    _lib.StartTestGroup("Do transactions")

    transactions.GetUnapprovedTransactionsEmpty(datadir)
    
    tx1 = _sql.ExecuteSQL(datadir,address,"CREATE TABLE test (a INT auto_increment PRIMARY KEY, b VARCHAR(20))")
    
    # check new table exists
    tables = _lib.DBGetRows(datadir,"SHOW TABLES")
    found = False
    for table in tables:
        if table[0] == "test":
            found = True
            break
    
    _lib.FatalAssert(found, "Table not found in the DB")
    
    # now add data and make a block 
    _sql.ExecuteSQL(datadir,address,"INSERT INTO test SET b='row1'")
    _sql.ExecuteSQL(datadir,address,"INSERT INTO test SET b='row2', a=2")
    _sql.ExecuteSQL(datadir,address,"INSERT INTO test  (b) values ('row3')")
    _sql.ExecuteSQL(datadir,address,"INSERT INTO test  (a, b) values (4, 'row4')")
    _sql.ExecuteSQL(datadir,address,"INSERT INTO test (a, b) values (8, 'row5')")
    
    _sql.ExecuteSQL(datadir,address,"UPDATE test SET b='row1_u1' where a=1")
    _sql.ExecuteSQL(datadir,address,"UPDATE test SET b='row2_u1' where a = '2'")
    
    _sql.ExecuteSQL(datadir,address,"UPDATE test SET b='row1_u2' where a= 1")
    
    _sql.ExecuteSQL(datadir,address,"delete from test where a=3")
    
    rows = _lib.DBGetRows(datadir,"SELECT * FROM test")
    
    _lib.FatalAssert(len(rows) == 4, "Must be 4 rows in a table")
    
    blockchash = _blocks.MintBlock(datadir,address)
    transactions.GetUnapprovedTransactionsEmpty(datadir)
    
    # test execution when transactions are already in a block
    _sql.ExecuteSQLFailure(datadir,address,"INSERT INTO test SET b='row2', a=2")
    _sql.ExecuteSQLFailure(datadir,address,"delete from test where a=3")
    _sql.ExecuteSQLFailure(datadir,address,"UPDATE test SET b='upd' where a=  3")
    _sql.ExecuteSQLFailure(datadir,address,"UPDATE test SET b='upd2', a=3 where a=  2")# we don't allow to change key value
    
    _sql.ExecuteSQL(datadir,address,"INSERT INTO test (a, b) values (6, 'row6')")
    _sql.ExecuteSQL(datadir,address,"UPDATE test SET b='row8_u1' where a=8")
    _sql.ExecuteSQL(datadir,address,"delete from test where a=2")
    _sql.ExecuteSQL(datadir,address,"UPDATE test SET b='row8_u2' where a=8")
    _sql.ExecuteSQL(datadir,address,"UPDATE test SET b='row6_u1' where a=6")
    
    
    
    #_lib.RemoveTestFolder(datadir)
    _lib.EndTestGroupSuccess()
    

    
Ejemplo n.º 5
0
def Make5BlocksBC():
    datadir = _lib.CreateTestFolder()
    
    _lib.StartTest("Create first address")
    res = _lib.ExecuteNode(['createwallet','-configdir',datadir])
    _lib.FatalAssertSubstr(res,"Your new address","Address creation returned wrong result")

    # get address from this response 
    match = re.search( r'.+: (.+)', res)

    if not match:
        _lib.Fatal("Address can not be found in "+res)
        
    address = match.group(1)

    dbconfig = _lib.GetDBCredentials(datadir)

    _lib.StartTest("Create blockchain")
    res = _lib.ExecuteNode(['initblockchain','-configdir',datadir, 
                            '-minter', address, 
                            '-mysqlhost', dbconfig['host'], 
                            '-mysqlport', dbconfig['port'],
                            '-mysqluser', dbconfig['user'],
                            '-mysqlpass', dbconfig['password'],
                            '-mysqldb', dbconfig['database'],
                            '-logs','trace'])
    
    _lib.FatalAssertSubstr(res,"Done!","Blockchain init failed")
    
    # create another 3 addresses
    address2 = transactions.CreateWallet(datadir)
    address3 = transactions.CreateWallet(datadir)

    _lib.StartTestGroup("Do transfers")

    transactions.GetUnapprovedTransactionsEmpty(datadir)
    
    amount1 = '1'
    amount2 = '2'
    amount3 = '3'
    
    _lib.StartTestGroup("Send 1 transaction")
    
    # one TX in first block
    txid1 = _transfers.Send(datadir,address,address2,amount1)
    txlist = transactions.GetUnapprovedTransactions(datadir)
    _lib.FatalAssert(len(txlist) == 1,"Should be 1 unapproved transaction")
    
    blockchash = _blocks.MintBlock(datadir,address)
    
    blockshashes = _blocks.GetBlocks(datadir)
    
    _lib.FatalAssert(len(blockshashes) == 2,"Should be 2 blocks in blockchain")
    
    _lib.StartTestGroup("Send 2 transactions")
    # 2 TX in second block
    txid2 = _transfers.Send(datadir,address,address3,amount2)
    
    txlist = transactions.GetUnapprovedTransactions(datadir)
    _lib.FatalAssert(len(txlist) == 1,"Should be 1 unapproved transaction")
    
    txid3 = _transfers.Send(datadir,address,address3,amount3)
    
    txlist = transactions.GetUnapprovedTransactions(datadir)
    
    _lib.FatalAssert(len(txlist) == 2,"Should be 2 unapproved transaction")
    
    blockchash = _blocks.MintBlock(datadir,address)
    
    blockshashes = _blocks.GetBlocks(datadir)
    
    _lib.FatalAssert(len(blockshashes) == 3,"Should be 3 blocks in blockchain")
   
    _lib.StartTestGroup("Send 3 transactions")
    
    microamount = 0.01
    
    txid1 = _transfers.Send(datadir,address,address2,microamount)
    txid2 = _transfers.Send(datadir,address2,address3,microamount)
    txid3 = _transfers.Send(datadir,address3,address,microamount)
    
    txlist = transactions.GetUnapprovedTransactions(datadir)
    
    _lib.FatalAssert(len(txlist) == 3,"Should be 3 unapproved transaction")
    
    blockchash = _blocks.MintBlock(datadir,address)
    transactions.GetUnapprovedTransactionsEmpty(datadir)
    
    blockshashes = _blocks.GetBlocks(datadir)
    
    _lib.FatalAssert(len(blockshashes) == 4,"Should be 4 blocks in blockchain")
    
    _lib.StartTestGroup("Send 4 transactions. Random value")
    
    microamountmax = 0.01
    microamountmin = 0.0095
    
    a1 = round(random.uniform(microamountmin, microamountmax),8)
    a2 = round(random.uniform(microamountmin, microamountmax),8)
    a3 = round(random.uniform(microamountmin, microamountmax),8)
    a4 = round(random.uniform(microamountmin, microamountmax),8)
    txid1 = _transfers.Send(datadir,address,address2,a1)
    txid2 = _transfers.Send(datadir,address2,address3,a2)
    txid3 = _transfers.Send(datadir,address3,address,a3)
    txid3 = _transfers.Send(datadir,address3,address,a4)
    
    txlist = transactions.GetUnapprovedTransactions(datadir)
    
    _lib.FatalAssert(len(txlist) == 4,"Should be 4 unapproved transaction")
    
    if txid1 not in txlist.keys():
        _lib.Fatal("Transaction 1 is not in the list of transactions after iteration "+str(i))

    if txid2 not in txlist.keys():
        _lib.Fatal("Transaction 2 is not in the list of transactions after iteration "+str(i))

    if txid3 not in txlist.keys():
        _lib.Fatal("Transaction 3 is not in the list of transactions after iteration "+str(i))
        
    blockchash = _blocks.MintBlock(datadir,address)
    transactions.GetUnapprovedTransactionsEmpty(datadir)
    
    blockshashes = _blocks.GetBlocks(datadir)
    
    _lib.FatalAssert(len(blockshashes) == 5,"Should be 5 blocks in blockchain")
    
    _lib.StartTestGroup("Send 5 transactions. Random value")
    
    txid1 = _transfers.Send(datadir,address,address2,a4)
    txid2 = _transfers.Send(datadir,address2,address3,a3)
    txid3 = _transfers.Send(datadir,address3,address,a2)
    txid3 = _transfers.Send(datadir,address3,address,a1)
    txid1 = _transfers.Send(datadir,address,address2,a1)
    
    blockchash = _blocks.MintBlock(datadir,address)
    transactions.GetUnapprovedTransactionsEmpty(datadir)
    
    blockshashes = _blocks.GetBlocks(datadir)
    
    _lib.FatalAssert(len(blockshashes) == 6,"Should be 6 blocks in blockchain")
    
    dstdir = _lib.getCurrentDir()+"/datafortests/bcwith4blocks/"
    
    copyfile(datadir+"/wallet.dat", dstdir+"wallet.t")
    DumpBCDB(datadir, dstdir+"db.sql")
    #copyfile(datadir+"/nodeslist.db", dstdir+"nodeslist.t")
    #copyfile(datadir+"/blockchain.db", dstdir+"blockchain.t")
    
    return [datadir, address, address2, address3]