Пример #1
0
def gusd_init_print(money):
    web3 = g_web3
    with grpc.insecure_channel(BANK_SERVER) as channel:
        stub = bank_pb2_grpc.bankStub(channel)
        response = stub.deposit(
            bank_pb2.depositRequest(account=COLLECTIVE_BANK_ACCOUNT,
                                    value=money))
        print("COLLECTIVE_BANK_ACCOUNT          deposit: " + response.message +
              ", " + str(response.balance))

        response = stub.deposit(
            bank_pb2.depositRequest(account=REGULATORY_BANK_ACCOUNT, value=0))
        print("REGULATORY_BANK_ACCOUNT          deposit: " + response.message +
              ", " + str(response.balance))

        response = stub.transfer(
            bank_pb2.transferRequest(fromAccount=COLLECTIVE_BANK_ACCOUNT,
                                     toAccount=REGULATORY_BANK_ACCOUNT,
                                     value=money))
        print("COLLECTIVE_BANK_ACCOUNT transfer REGULATORY_BANK_ACCOUNT " +
              str(money) + ": " + response.message + ", " +
              str(response.balance))

        web3.personal.unlockAccount(SWEEPER_ETH_ACCOUNT, SWEEPER_ETH_PASSWORD)
        txhash = PrintLimiterContract.functions.limitedPrint(
            SWEEPER_ETH_ACCOUNT, money).transact({'from': SWEEPER_ETH_ACCOUNT})
        web3.eth.waitForTransactionReceipt(txhash)
Пример #2
0
def testBalance():
    with grpc.insecure_channel('172.16.1.176:50052') as channel:
        stub = bank_pb2_grpc.bankStub(channel)

        # #查询归集帐号blance
        # response = stub.balance(bank_pb2.balanceRequest(account=control.COLLECTIVE_BANK_ACCOUNT))
        # print("balanceRequest    : account=COLLECTIVE_BANK_ACCOUNT")
        # print("received          : " + response.message + ", " +str(response.balance));
        #
        # # 查询监管帐号blance
        # response = stub.balance(bank_pb2.balanceRequest(account=control.REGULATORY_BANK_ACCOUNT))
        # print("balanceRequest    : account=REGULATORY_BANK_ACCOUNT")
        # print("received          : " + response.message + ", " +str(response.balance));

        control.gusd_init()

        balance = control.bankBlance(control.COLLECTIVE_BANK_ACCOUNT)
        # if(balance!=None):
        #     print("COLLECTIVE_BANK_ACCOUNT balance:%d"%(balance))

        balance = control.bankBlance(control.REGULATORY_BANK_ACCOUNT)
        # if (balance != None):
        #     print("REGULATORY_BANK_ACCOUNT balance:%d" % (balance))

        gusdBalance = control.getGUSDBalance(control.SWEEPER_ETH_ACCOUNT)

        # totalSupply=control.getTotalSupply()

        totalSupply = control.get_gusd_print()
Пример #3
0
def testAddUser2():
    # 测试注册用户
    #创建bank_yl002用户,并存入10000
    with grpc.insecure_channel('172.16.1.176:50052') as channel:
        stub = bank_pb2_grpc.bankStub(channel)

        #创建bank_yl002 银行用户,存款10000
        response = stub.deposit(
            bank_pb2.depositRequest(account='bank_yl002', value=10000))
        print("depositRequest    : account='bank_yl002',value=10000")
        print("received          : " + response.message + ", " +
              str(response.balance) + ", " + str(response.recordIndex))
        print("-------------------------------------------")

    # 对应创建genemi_yl002 genemi系统用户
    # 钱包上的地址是 account21
    with grpc.insecure_channel('172.16.1.175:50053') as channel:
        stub = gemini_pb2_grpc.geminiStub(channel)
        response = stub.register(
            gemini_pb2.registerRequest(
                account='genemi_yl002',
                password='******',
                mail="*****@*****.**",
                phone="00000000002",
                withdrawBankAccount="bank_yl002",
                withdrawEthaddress="0x16DBc3D1e32002abf22E75a2131c8f64aD67d99a"
            ))
Пример #4
0
def testAddUser1():
    with grpc.insecure_channel('172.16.1.176:50052') as channel:
        stub = bank_pb2_grpc.bankStub(channel)

        # 创建bank_yl001 银行用户,存款10000
        response = stub.deposit(
            bank_pb2.depositRequest(account='bank_yl001', value=10000))
        print("depositRequest    : account='bank_yl001',value=10000")
        print("received          : " + response.message + ", " +
              str(response.balance) + ", " + str(response.recordIndex))
        print("-------------------------------------------")

    # 对应创建genemi_yl001 genemi系统用户
    # 钱包上的地址是 account20
    with grpc.insecure_channel('172.16.1.175:50053') as channel:
        stub = gemini_pb2_grpc.geminiStub(channel)

        response = stub.register(
            gemini_pb2.registerRequest(
                account='genemi_yl001',
                password='******',
                mail="*****@*****.**",
                phone="00000000001",
                withdrawBankAccount="bank_yl001",
                withdrawEthaddress="0xB0B5Cc397ED952587a4B1A17AFDdF01F99DA4531"
            ))
Пример #5
0
def bankBlance(account_):
    try:
        with grpc.insecure_channel(BANK_SERVER) as channel:
            stub = bank_pb2_grpc.bankStub(channel)

            response = stub.balance(bank_pb2.balanceRequest(account=account_))

            if (response.message != 'OK'):
                return None

            g_log.info(account_ + " bank balance:" + str(response.balance))
            return response.balance
    except Exception as e:
        g_log.error("something err:%s" % (e))
        return None
Пример #6
0
def testDepositUSD():
    with grpc.insecure_channel('172.16.1.176:50052') as channel:
        stub = bank_pb2_grpc.bankStub(channel)

        #查询bank_yl001银行账户balance
        response = stub.balance(bank_pb2.balanceRequest(account="bank_yl001"))
        print("balanceRequest    : account=bank_yl001")
        print("received          : " + response.message + ", " +
              str(response.balance))

        #查询COLLECTIVE_BANK_ACCOUNT银行账户balance
        response = stub.balance(
            bank_pb2.balanceRequest(account=control.COLLECTIVE_BANK_ACCOUNT))
        print("balanceRequest    : account=control.COLLECTIVE_BANK_ACCOUNT")
        print("received          : " + response.message + ", " +
              str(response.balance))

        #测试USD存款
        #bank_yl001银行用户向genemi归集账户转账1000
        response = stub.transfer(
            bank_pb2.transferRequest(fromAccount='bank_yl001',
                                     toAccount=control.COLLECTIVE_BANK_ACCOUNT,
                                     value=1000))
        print(
            "transferRequest   : fromAccount='bank_yl001',toAccount='control.COLLECTIVE_BANK_ACCOUNT',value=100"
        )
        print("received          : " + response.message + ", " +
              str(response.balance) + ", " + str(response.recordIndex))

        # 查询bank_yl001银行账户balance
        response = stub.balance(
            bank_pb2.balanceRequest(account=control.COLLECTIVE_BANK_ACCOUNT))
        print("balanceRequest    : account=control.COLLECTIVE_BANK_ACCOUNT")
        print("received          : " + response.message + ", " +
              str(response.balance))

        #查询COLLECTIVE_BANK_ACCOUNT银行账户balance
        response = stub.balance(bank_pb2.balanceRequest(account="bank_yl001"))
        print("balanceRequest    : account=bank_yl001")
        print("received          : " + response.message + ", " +
              str(response.balance))
        print("-------------------------------------------")
Пример #7
0
def bankTransfer(fromAccount_, toAccount_, value_):
    try:
        with grpc.insecure_channel(BANK_SERVER) as channel:
            stub = bank_pb2_grpc.bankStub(channel)

            response = stub.transfer(
                bank_pb2.transferRequest(fromAccount=fromAccount_,
                                         toAccount=toAccount_,
                                         value=value_))
            # print("received          : " + response.message + ", " + str(response.balance));
            g_log.info(fromAccount_ + " send " + str(value_) + " usd to " +
                       toAccount_)

            if (response.message != 'OK'):
                return None

            return response
    except Exception as e:
        g_log.info(fromAccount_ + "send " + str(value_) + " usd to " +
                   toAccount_)
        g_log.error("something err:%s" % (e))
        return None
Пример #8
0
    def test_WithdrawalUSD10000(self):
        gusd = 0
        usd = 0
        gemini_usd = 0
        gemini_user_usd = 0
        gemini_user_gusd = 0
        bank_usd = 0
        #从gemini系统查询genemi_yl001的USD余额
        with grpc.insecure_channel('172.16.1.175:50053') as channel:
            stub = gemini_pb2_grpc.geminiStub(channel)
            response = stub.balance(
                gemini_pb2.balanceRequest(account='genemi_yl001'))
            print("balanceRequest : account='genemi_yl001'")
            print("received          : " + response.message + ", USD:" +
                  str(response.usd) + ", GUSD:" + str(response.gusd))
            print("-------------------------------------------")
            gemini_user_usd = response.usd
            gemini_user_gusd = response.gusd
            self.assertEqual(response.message, "OK")

        #向银行查询bank_yl001余额
        with grpc.insecure_channel('172.16.1.176:50052') as channel:
            stub = bank_pb2_grpc.bankStub(channel)
            response = stub.balance(
                bank_pb2.balanceRequest(account="bank_yl001"))
            print("balanceRequest    : account=bank_yl001")
            print("received          : " + response.message + ", " +
                  str(response.balance))
            bank_usd = response.balance
            print("-------------------------------------------")
            self.assertEqual(response.message, "OK")

        #从gemini系统genemi_yl001用户提现1000到bank_yl001
        with grpc.insecure_channel('172.16.1.175:50053') as channel:
            stub = gemini_pb2_grpc.geminiStub(channel)
            response = stub.withdrawalUSD(
                gemini_pb2.withdrawalUSDRequest(
                    account='genemi_yl001',
                    withdrawBankAccount="bank_yl001",
                    usd=10000))
            print(
                "withdrawalUSD : account='genemi_yl001' to bankAccount='bank_yl001' value=10000"
            )
            print("received          : " + response.message + ", USD:" +
                  str(response.usd) + ", GUSD:" + str(response.gusd))
            print("-------------------------------------------")
            self.assertEqual(response.message, "OK")

        #向genemi查询genemi_yl001余额
        with grpc.insecure_channel('172.16.1.175:50053') as channel:
            stub = gemini_pb2_grpc.geminiStub(channel)
            response = stub.balance(
                gemini_pb2.balanceRequest(account='genemi_yl001'))
            print("balanceRequest : account='genemi_yl001'")
            print("received          : " + response.message + ", USD:" +
                  str(response.usd) + ", GUSD:" + str(response.gusd))
            print("-------------------------------------------")
            self.assertEqual(response.usd, gemini_user_usd - 10000)
            self.assertEqual(response.gusd, gemini_user_gusd)
            self.assertEqual(response.message, "OK")

        #向银行查询bank_yl001余额
        with grpc.insecure_channel('172.16.1.176:50052') as channel:
            stub = bank_pb2_grpc.bankStub(channel)
            response = stub.balance(
                bank_pb2.balanceRequest(account="bank_yl001"))
            print("balanceRequest    : account=bank_yl001")
            print("received          : " + response.message + ", " +
                  str(response.balance))
            self.assertEqual(response.balance, bank_usd + 10000)
            print("-------------------------------------------")
            self.assertEqual(response.message, "OK")