Esempio n. 1
0
    def test_trx_vote_witness(self, app):
        tx = app.packContract(
            tron.Transaction.Contract.VoteWitnessContract,
            contract.VoteWitnessContract(
                owner_address=bytes.fromhex(app.getAccount(0)['addressHex']),
                votes=[
                    contract.VoteWitnessContract.Vote(
                        vote_address=bytes.fromhex(app.address_hex("TKSXDA8HfE9E1y39RczVQ1ZascUEtaSToF")),
                        vote_count=100
                    ),
                    contract.VoteWitnessContract.Vote(
                        vote_address=bytes.fromhex(app.address_hex("TE7hnUtWRRBz3SkFrX8JESWUmEvxxAhoPt")),
                        vote_count=100
                    ),
                    contract.VoteWitnessContract.Vote(
                        vote_address=bytes.fromhex(app.address_hex("TTcYhypP8m4phDhN6oRexz2174zAerjEWP")),
                        vote_count=100
                    ),
                    contract.VoteWitnessContract.Vote(
                        vote_address=bytes.fromhex(app.address_hex("TY65QiDt4hLTMpf3WRzcX357BnmdxT2sw9")),
                        vote_count=100
                    ),
                ]
            )
        )

        data, status = app.sign(app.getAccount(0)['path'], tx)
        validSignature, txID = validateSignature.validate(tx,data[0:65],app.getAccount(0)['publicKey'][2:])
        assert(validSignature == True)
Esempio n. 2
0
    def test_trx_withdraw_balance(self, app):
        tx = app.packContract(
            tron.Transaction.Contract.WithdrawBalanceContract,
            contract.WithdrawBalanceContract(
                owner_address=bytes.fromhex(app.getAccount(0)['addressHex'])
            )
        )

        data, status = app.sign(app.getAccount(0)['path'], tx)
        validSignature, txID = validateSignature.validate(tx,data[0:65],app.getAccount(0)['publicKey'][2:])
        assert(validSignature == True)
Esempio n. 3
0
    def test_trx_unfreeze_balance_bw(self, app):
        tx = app.packContract(
            tron.Transaction.Contract.UnfreezeBalanceContract,
            contract.UnfreezeBalanceContract(
                owner_address=bytes.fromhex(app.getAccount(0)['addressHex']),
                resource=contract.BANDWIDTH,
            )
        )

        data, status = app.sign(app.getAccount(0)['path'], tx)
        validSignature, txID = validateSignature.validate(tx,data[0:65],app.getAccount(0)['publicKey'][2:])
        assert(validSignature == True)
Esempio n. 4
0
    def test_trx_proposal_delete(self, app):
        tx = app.packContract(
            tron.Transaction.Contract.ProposalDeleteContract,
            contract.ProposalDeleteContract(
                owner_address=bytes.fromhex(app.getAccount(0)['addressHex']),
                proposal_id=10,
            )
        )

        data, status = app.sign(app.getAccount(0)['path'], tx)
        validSignature, txID = validateSignature.validate(tx,data[0:65],app.getAccount(0)['publicKey'][2:])
        assert(validSignature == True)
Esempio n. 5
0
 def test_trx_send_wrong_path(self, app):
     tx = app.packContract(
         tron.Transaction.Contract.TransferContract,
         contract.TransferContract(
             owner_address=bytes.fromhex(app.getAccount(0)['addressHex']),
             to_address=bytes.fromhex(app.getAccount(0)['addressHex']),
             amount=100000000
         )
     )
     data, status = app.sign(app.getAccount(0)['path'], tx)
     validSignature, txID = validateSignature.validate(tx,data[0:65],app.getAccount(0)['publicKey'][2:])
     assert(validSignature == False)
Esempio n. 6
0
    def test_trx_account_update(self, app):
        tx = app.packContract(
            tron.Transaction.Contract.AccountUpdateContract,
            contract.AccountUpdateContract(
                account_name=b'CryptoChainTest',
                owner_address=bytes.fromhex(app.getAccount(0)['addressHex']),
            )
        )

        data, status = app.sign(app.getAccount(0)['path'], tx)
        validSignature, txID = validateSignature.validate(tx,data[0:65],app.getAccount(0)['publicKey'][2:])
        assert(validSignature == True)
Esempio n. 7
0
    def test_vs_proposal_create(self, app):
        tx = app.packContract(
            vision.Transaction.Contract.ProposalCreateContract,
            contract.ProposalCreateContract(
                owner_address=bytes.fromhex(app.getAccount(0)['addressHex']),
                parameters={1: 100000, 2: 400000}
            )
        )

        data, status = app.sign(app.getAccount(0)['path'], tx)
        validSignature, txID = validateSignature.validate(tx,data[0:65],app.getAccount(0)['publicKey'][2:])
        assert(validSignature == True)
Esempio n. 8
0
 def test_trx_send_asset_without_name(self, app):
     tx = app.packContract(
         tron.Transaction.Contract.TransferAssetContract,
         contract.TransferAssetContract(
             owner_address=bytes.fromhex(app.getAccount(0)['addressHex']),
             to_address=bytes.fromhex(app.getAccount(0)['addressHex']),
             amount=1000000,
             asset_name="1002000".encode()
         )
     )
     data, status = app.sign(app.getAccount(0)['path'], tx)
     validSignature, txID = validateSignature.validate(tx,data[0:65],app.getAccount(0)['publicKey'][2:])
     assert(validSignature == True)
Esempio n. 9
0
 def test_trx_send_with_data_field(self, app):
     tx = app.packContract(
         tron.Transaction.Contract.TransferContract,
         contract.TransferContract(
             owner_address=bytes.fromhex(app.getAccount(0)['addressHex']),
             to_address=bytes.fromhex(app.getAccount(0)['addressHex']),
             amount=100000000
         ),
         b'CryptoChain-TronSR Ledger Transactions Tests'
     )
     data, status = app.sign(app.getAccount(0)['path'], tx)
     validSignature, txID = validateSignature.validate(tx,data[0:65],app.getAccount(0)['publicKey'][2:])
     assert(validSignature == True)
Esempio n. 10
0
    def test_vs_unfreeze_balance_delegate_entropy(self, app):
        tx = app.packContract(
            vision.Transaction.Contract.UnfreezeBalanceContract,
            contract.UnfreezeBalanceContract(
                owner_address=bytes.fromhex(app.getAccount(0)['addressHex']),
                resource=contract.ENTROPY,
                receiver_address=bytes.fromhex(app.getAccount(1)['addressHex']),
            )
        )

        data, status = app.sign(app.getAccount(0)['path'], tx)
        validSignature, txID = validateSignature.validate(tx,data[0:65],app.getAccount(0)['publicKey'][2:])
        assert(validSignature == True)
Esempio n. 11
0
    def test_trx_trc20_approve(self, app):
        tx = app.packContract(
            tron.Transaction.Contract.TriggerSmartContract,
            contract.TriggerSmartContract(
                owner_address=bytes.fromhex(app.getAccount(0)['addressHex']),
                contract_address=bytes.fromhex(app.address_hex("TBoTZcARzWVgnNuB9SyE3S5g1RwsXoQL16")),
                data=bytes.fromhex("095ea7b3000000000000000000000000364b03e0815687edaf90b81ff58e496dea7383d700000000000000000000000000000000000000000000000000000000000f4240")
            )
        )

        data, status = app.sign(app.getAccount(0)['path'], tx)
        validSignature, txID = validateSignature.validate(tx,data[0:65],app.getAccount(0)['publicKey'][2:])
        assert(validSignature == True)
Esempio n. 12
0
    def test_trx_unknown_trc20_send(self, app):
        tx = app.packContract(
            tron.Transaction.Contract.TriggerSmartContract,
            contract.TriggerSmartContract(
                owner_address=bytes.fromhex(app.getAccount(0)['addressHex']),
                contract_address=bytes.fromhex(app.address_hex("TVGLX58e3uBx1fmmwLCENkrgKqmpEjhtfG")),
                data=bytes.fromhex("a9059cbb000000000000000000000000364b03e0815687edaf90b81ff58e496dea7383d700000000000000000000000000000000000000000000000000000000000f4240")
            )
        )

        data, status = app.sign(app.getAccount(0)['path'], tx)
        validSignature, txID = validateSignature.validate(tx,data[0:65],app.getAccount(0)['publicKey'][2:])
        assert(validSignature == True)
Esempio n. 13
0
 def test_trx_exchange_create(self, app):
     tx = app.packContract(
         tron.Transaction.Contract.ExchangeCreateContract,
         contract.ExchangeCreateContract(
             owner_address=bytes.fromhex(app.getAccount(0)['addressHex']),
             first_token_id="_".encode(),
             first_token_balance=10000000000,
             second_token_id="1000166".encode(),
             second_token_balance=10000000
         )
     )
     data, status = app.sign(app.getAccount(0)['path'], tx)
     validSignature, txID = validateSignature.validate(tx,data[0:65],app.getAccount(0)['publicKey'][2:])
     assert(validSignature == True)
Esempio n. 14
0
    def test_trx_freeze_balance_energy(self, app):
        tx = app.packContract(
            tron.Transaction.Contract.FreezeBalanceContract,
            contract.FreezeBalanceContract(
                owner_address=bytes.fromhex(app.getAccount(0)['addressHex']),
                frozen_balance=10000000000,
                frozen_duration=3,
                resource=contract.ENERGY
                )
        )

        data, status = app.sign(app.getAccount(0)['path'], tx)
        validSignature, txID = validateSignature.validate(tx,data[0:65],app.getAccount(0)['publicKey'][2:])
        assert(validSignature == True)
Esempio n. 15
0
 def test_trx_exchange_withdraw(self, app):
     tx = app.packContract(
         tron.Transaction.Contract.ExchangeWithdrawContract,
         contract.ExchangeWithdrawContract(
             owner_address=bytes.fromhex(app.getAccount(0)['addressHex']),
             exchange_id=6,
             token_id="1000166".encode(),
             quant=1000000
             )
     )
     exchangeSignature = ["08061207313030303136361a0b43727970746f436861696e20002a015f3203545258380642473045022100fe276f30a63173b2440991affbbdc5d6d2d22b61b306b24e535a2fb866518d9c02205f7f41254201131382ec6c8b3c78276a2bb136f910b9a1f37bfde192fc448793"]
     data, status = app.sign(app.getAccount(0)['path'], tx, exchangeSignature)
     validSignature, txID = validateSignature.validate(tx,data[0:65],app.getAccount(0)['publicKey'][2:])
     assert(validSignature == True)
Esempio n. 16
0
 def test_vs_send_permissioned(self, app):
     tx = app.packContract(
         vision.Transaction.Contract.TransferContract,
         contract.TransferContract(
             owner_address=bytes.fromhex(app.getAccount(0)['addressHex']),
             to_address=bytes.fromhex(app.getAccount(0)['addressHex']),
             amount=100000000
         ),
         None,
         2
     )
     data, status = app.sign(app.getAccount(0)['path'], tx)
     assert(status == 0x9000)
     validSignature, txID = validateSignature.validate(tx,data[0:65],app.getAccount(0)['publicKey'][2:])
     assert(validSignature == True)
Esempio n. 17
0
 def test_trx_send_asset_with_name(self, app):
     tx = app.packContract(
         tron.Transaction.Contract.TransferAssetContract,
         contract.TransferAssetContract(
             owner_address=bytes.fromhex(app.getAccount(0)['addressHex']),
             to_address=bytes.fromhex(app.getAccount(0)['addressHex']),
             amount=1000000,
             asset_name="1002000".encode()
         )
     )
     # BTT token ID 1002000 - 6 decimals
     tokenSignature = ["0a0a426974546f7272656e7410061a46304402202e2502f36b00e57be785fc79ec4043abcdd4fdd1b58d737ce123599dffad2cb602201702c307f009d014a553503b499591558b3634ceee4c054c61cedd8aca94c02b"]
     data, status = app.sign(app.getAccount(0)['path'], tx, tokenSignature)
     validSignature, txID = validateSignature.validate(tx,data[0:65],app.getAccount(0)['publicKey'][2:])
     assert(validSignature == True)
Esempio n. 18
0
 def test_trx_custom_contract(self, app):
     tx = app.packContract(
         tron.Transaction.Contract.TriggerSmartContract,
         contract.TriggerSmartContract(
             owner_address=bytes.fromhex(app.getAccount(0)['addressHex']),
             contract_address=bytes.fromhex(app.address_hex("TTg3AAJBYsDNjx5Moc5EPNsgJSa4anJQ3M")),
             data=bytes.fromhex('{:08x}{:064x}'.format(
                 0x0a857040,
                 int(10001)
                 ))
         )
     )
     
     data, status = app.sign(app.getAccount(0)['path'], tx)
     validSignature, txID = validateSignature.validate(tx,data[0:65],app.getAccount(0)['publicKey'][2:])
     assert(validSignature == True)
Esempio n. 19
0
 def test_trx_exchange_create_with_token_name(self, app):
     tx = app.packContract(
         tron.Transaction.Contract.ExchangeCreateContract,
         contract.ExchangeCreateContract(
             owner_address=bytes.fromhex(app.getAccount(0)['addressHex']),
             first_token_id="_".encode(),
             first_token_balance=10000000000,
             second_token_id="1000166".encode(),
             second_token_balance=10000000
         )
     )
     tokenSignature = ["0a0354525810061a463044022037c53ecb06abe1bfd708bd7afd047720b72e2bfc0a2e4b6ade9a33ae813565a802200a7d5086dc08c4a6f866aad803ac7438942c3c0a6371adcb6992db94487f66c7",
               "0a0b43727970746f436861696e10001a4730450221008417d04d1caeae31f591ae50f7d19e53e0dfb827bd51c18e66081941bf04639802203c73361a521c969e3fd7f62e62b46d61aad00e47d41e7da108546d954278a6b1"]
     data, status = app.sign(app.getAccount(0)['path'], tx, tokenSignature)
     validSignature, txID = validateSignature.validate(tx,data[0:65],app.getAccount(0)['publicKey'][2:])
     assert(validSignature == True)
####################
logger.debug('\n\SmartContract Trigger: Deposit TRX in TWM Contract')
data = '{:08x}'.format(0xd0e30db0)
tx = stub.TriggerContract(
    contract.TriggerSmartContract(
        owner_address=bytes.fromhex(accounts[1]['addressHex']),
        contract_address=bytes.fromhex(
            address_hex("TTg3AAJBYsDNjx5Moc5EPNsgJSa4anJQ3M")),
        call_value=1000000,
        data=bytes.fromhex(data)))

raw_tx, result = ledgerSign(accounts[1]['path'], tx.transaction)
tx.transaction.signature.extend([bytes(result[0:65])])
#r = stub.BroadcastTransaction(tx.transaction)

validSignature, txID = validateSignature.validate(raw_tx, result[0:65],
                                                  accounts[1]['publicKey'][2:])
logger.debug('- RAW: {}'.format(raw_tx))
logger.debug('- txID: {}'.format(txID))
logger.debug('- Signature: {}'.format(binascii.hexlify(result[0:65])))
if (validSignature):
    logger.debug('- Valid: {}'.format(validSignature))
else:
    logger.error('- Valid: {}'.format(validSignature))
    sys.exit(0)

######################
# TWM Deposit Token  #
######################
logger.debug('\n\SmartContract Trigger: Deposit BTT in TWM Contract')
data = '{:08x}'.format(0xd0e30db0)
tx = stub.TriggerContract(