Grinnode-live / 2020-grin-bug-bash-challenge

Finding bugs in Grin-Wallet & Grin-nodes for a bounty prior to Grin fork v5.
3 stars 1 forks source link

[GRIN-Wallet][Owner API] Testing non-default account #41

Closed stakervali closed 3 years ago

stakervali commented 3 years ago

Description Testing the retrieve payment proof method from the Owner API

Prerequisites

GRIN-Node
GRIN-Wallet

Test procedure

Create a new account with name other_account. Get address of new account with account flag grin-wallet -a other_account Make a transaction with new account

Expected result:

grin-wallet address command should return a new address. New transaction should be reported on new account's info (grin-wallet -a other_account info).

Include the output of command

grin-wallet -V

and your environment

uname -a
mojitoo commented 3 years ago

OS : Mac os Catalina Grin wallet version : v5.0.0

create a new account :

The account command is used to manage wallet accounts. To create a new account, pass the argument -c --create.

grin-wallet account -c other_account

check account creation :

Let's print a list of your existing accounts and check the newly created account .

grin-wallet account
Password: 

____ Wallet Accounts ____

 Name          | Parent BIP-32 Derivation Path 
---------------+-------------------------------
 default       | m/0/0 
 newaccount    | m/1/0 
 other_account | m/2/0 

Command 'account' completed successfully

get the new address :

grin-wallet account -a other_account address
Password: 

Address for account - other_account
-------------------------------------
grin1um0zd6mqp8edv6jkm72uu9hfty23dyr0yct4zjyfwm8av37yay8sewrjfc

Command 'address' completed successfully

check account TX history (0 transaction) :

account history should be empty

grin-wallet account -a other_account txs
Password: 
20201221 07:55:02.534 WARN grin_wallet_libwallet::api_impl::owner_updater - Scanning - 0% complete
20201221 07:55:03.517 WARN grin_wallet_libwallet::api_impl::owner_updater - Scanning - 99% complete
20201221 07:55:03.531 WARN grin_wallet_libwallet::api_impl::owner_updater - Scanning - 99% complete
20201221 07:55:03.533 WARN grin_wallet_libwallet::api_impl::owner_updater - Scanning Complete

Transaction Log - Account 'other_account' - Block Height: 1011582

Command 'txs' completed successfully

check account TX history (after 1 received transaction) :

grin-wallet account -a other_account txs

Password: 
20201221 08:08:36.430 WARN grin_wallet_libwallet::api_impl::owner_updater - Scanning - 0% complete
20201221 08:08:37.285 WARN grin_wallet_libwallet::api_impl::owner_updater - Scanning - 99% complete
20201221 08:08:37.301 WARN grin_wallet_libwallet::api_impl::owner_updater - Scanning - 99% complete
20201221 08:08:37.302 WARN grin_wallet_libwallet::api_impl::owner_updater - Scanning Complete

Transaction Log - Account 'other_account' - Block Height: 1011601
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Id  Type         Shared Transaction Id                 Creation Time        TTL Cutoff Height  Confirmed?  Confirmation Time  Num.    Num.     Amount    Amount   Fee   Net         Payment   Kernel                                                              Tx  
                                                                                                                               Inputs  Outputs  Credited  Debited        Difference  Proof                                                                         Data 
========================================================================================================================================================================================================================================================================
 0   Received Tx  e1b9a8d8-a2a7-47bc-b35d-2b6c317bb517  2020-12-21 07:07:30  None               false       None               0       1        0.2       0.0      None  0.2         None      0938b9317ee791c81e11bd8c0b529fa823f865305198805bd1524202a44489a524  None 
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Command 'txs' completed successfully
marekyggdrasil commented 3 years ago

@mojitoo terribly sorry for the confusion, this is Owner API case, could you run the wallet in listener mode and do it using api call with Python/NodeJS script?

( but I must say its nice to see something is working on Catalina... lol )

mojitoo commented 3 years ago

Prerequisites:

Step 1 (Runs the wallet's local web API)

grin-wallet owner_api
Password: 
20201220 07:55:46.473 WARN grin_wallet_controller::controller - Starting HTTP Foreign API on Owner server at 127.0.0.1:3420.
20201220 07:55:46.473 WARN grin_wallet_controller::controller - Starting HTTP Owner API server at 127.0.0.1:3420.
20201220 07:55:46.473 WARN grin_wallet_controller::controller - HTTP Owner listener started

HTTP Owner successfully started.

Create a new account with name other_account2

Before runnning the script, we need to make sure to edit the configuration.

change to your grin owner_api sercret file

api_sercet_file = '/Users/path/.grin/main/.owner_api_secret'

change to you wallet password

wallet_password = 'xxx'

call this following function at the end of wallet_v3.py

pp.pprint(wallet.create_account_path("other_account2"))

pyhton3 wallet_v3.py
   {'label': 'default', 'path': '0200000000000000000000000000000000'},
    {'label': 'newaccount', 'path': '0200000001000000000000000000000000'},
    {'label': 'other_account', 'path': '0200000002000000000000000000000000'},
    {'label': 'other_account2', 'path': '0200000003000000000000000000000000'}

Test was valid. new account was returned

Get address of the new account

call this following functions at the end of wallet_v3.py

pp.pprint(wallet.set_active_account("other_account2")) pp.pprint(wallet.get_slatepack_address())

True
'grin1cmj9hjm4xc4hxw443adjadat6syzrq3wy059ta2p3zyu67xcn8sqt06ufr'

Make a transaction with new account

args should be added like this and passed to init_send_tx method


args = {
                'src_acct_name': "other_account2",
                'amount': 100000000,
                'minimum_confirmations': 2,
                'max_outputs': 500,
                'num_change_outputs': 1,
                'selection_strategy_is_use_all': False,
                'target_slate_version': None,
                'ttl_blocks': None,
                'estimate_only': False,
                'payment_proof_recipient_address': None,
                'send_args': {
                    'dest': 'grin12wktxlyfx62wx48ldn55katd8zm5d6qfa6mupt9r4uul8eqxagsqct3je5',
                    'post_tx': True,
                    'fluff': True,
                    'skip_tor': True,
                }
            }

    wallet.open_wallet(None, wallet_password)

    result = wallet.init_send_tx(args)
    pp.pprint(result)
    # Create the slatepack that the recipient will need to when prompted during the receive command.
    # Empty array for recipients
    resp = wallet.create_slatepack_message(result, [])
    pp.pprint(resp)
    wallet.tx_lock_outputs(result)

after running the script, the following slatepack will be returned to be used along receive command on the receiver wallet.

python3 /Users/workstation/Downloads/wallet_v3.py 
{   'amt': '100000000',
    'fee': '23000000',
    'id': '4cf82a61-583c-4e58-b824-1291b1eac790',
    'sigs': [   {   'nonce': '0345fe2dc7044c150086cb010b786a113ee632f495b25341cbdacf2cb69979c009',
                    'xs': '031dbd2cc5fc2b263be5f1e9d859cb2e3d85e06d9c3cd37abfde4a7a62d9f9a516'}],
    'sta': 'S1',
    'ver': '4:3'}
('BEGINSLATEPACK. 6nU3nPs3ptRudLx 24J3dxtoGhT8YhU j6MwrjE1xfs4CGV '
 'wLE3RjTXmbnvZYq zj3fnCMraYQS2iS 7mj12GDHYF9K8y5 HPPcQ3Xz74HAPRM '
 '2t7trEshwU4s4DZ Mv6FgdAuSEye1MX jmN2TCdb2sXxrLN Kkd1YYDXBeHWH4z '
 'wZ9cc3h9sYbtBDX vo3rq7g3vptLZAh SPYSbUcH1iqUJqd jUW59YmAo. ENDSLATEPACK.')

by running txs command we can see that the transaction was init.

grin-wallet -a other_account2 txs
--------------------------------------------------------------------------------------
 2   Sent Tx      4cf82a61-583c-4e58-b824-1291b1eac790  2020-12-27 16:27:11  None               false       None                 1       1        0.027     0.15     0.023  -0.123      None      081dbd2cc5fc2b263be5f1e9d859cb2e3d85e06d9c3cd37abfde4a7a62d9f9a516  Yes 
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
mojitoo commented 3 years ago

@marekyggdrasil the last step "make transaction with new account", is it a received transaction or a send one ?

marekyggdrasil commented 3 years ago

Please use whatever the flow you find more convenient. Both of them will be tested separately anyway in https://github.com/Grinnode-live/2020-grin-bug-bash-challenge/issues/48 and https://github.com/Grinnode-live/2020-grin-bug-bash-challenge/issues/29

mojitoo commented 3 years ago

can you document the args structure i will need to provide to init_send_tx (self, args) please ? the link seems to not work : link

marekyggdrasil commented 3 years ago

@mojitoo there you go, here's the link to the docs, let me know if there is anything else I can help you with.

marekyggdrasil commented 3 years ago

@mojitoo I can see the updated in the comment. Well done! Closing.