The goal of this challenge is to write a test server that will run a test suite when receiving a particular request. Please write the server code in Rust, and create a docker file to build it as well as a docker-compose file to run it (even if it has only one service).

Steps of the Test Suite:

  1. Generate a new mnemonic and new receiving address for BTC and LavaUSD.

  2. Call the mutinynet faucet endpoint to receive some BTC and LavaUSD to the addresses generated in step 1.

    1. For Bitcoin:

      curl -X POST [<https://faucet.testnet.lava.xyz/mint-mutinynet>](<https://faucet.testnet.lava.xyz/mint-mutinynet>) \\ -H "Content-Type: application/json" \\ -d '{ "address": "tb1qxasf0jlsssl3xz8xvl8pmg8d8zpljqmervhtrr", "sats": 50000 }'
      
    2. For LavaUSD:

      curl -X POST [<https://faucet.testnet.lava.xyz/transfer-lava-usd>](<https://faucet.testnet.lava.xyz/transfer-lava-usd>) \\ -H "Content-Type: application/json" \\ -d '{ "pubkey": "CU9KRXJobqo1HVbaJwoWpnboLFXw3bef54xJ1dewXzcf" }'
      
  3. Download and install the CLI:

    # Install libpq-dev or similar
    
    sudo apt-get update; sudo apt-get install libpq-dev
    # 'brew install libpq' for macOS
    
    # Download CLI
    
    curl -o loans-borrower-cli <https://loans-borrower-cli.s3.amazonaws.com/loans-borrower-cli-linux>
    # 'curl -o loans-borrower-cli <https://loans-borrower-cli.s3.amazonaws.com/loans-borrower-cli-mac>' for macOS
    
    chmod +x ./loans-borrower-cli
    
  4. Create a new loan with the following command:

    MNEMONIC="<newly generated>" ./loans-borrower-cli --testnet --disable-backup-contracts borrow init --loan-capital-asset solana-lava-usd --ltv-ratio-bp 5000 --loan-duration-days 4 --loan-amount 2 --finalize
    
  5. Capture the contract-id from the std output via regex.

  6. Run the following command to repay the loan: MNEMONIC="<newly generated>" ./loans-borrower-cli --testnet --disable-backup-contracts borrow repay --contract-id $REPAY_CONTRACT_ID

  7. Run the following command, which will handle active contracts, detect that the loan has been repaid, update local storage, and then create the details JSON file for checking. MNEMONIC="<newly generated>" ./loans-borrower-cli --testnet --disable-backup-contracts get-contract --contract-id $REPAY_CONTRACT_ID --disable-contracts-backup --verbose --output-file ${EXPIRE_CONTRACT_ID}.json

  8. Check the newly created JSON file to ensure that it shows as 'Closed' and has a corresponding, collateral_repayment_tx, such as:

    {
      "Closed": {
    

    and

    "outcome": {   
    	"repayment": {
    		"collateral_repayment_txid": "60c27b7a5db7652c271de02120982e7f21a54eca5aa6d80177859a5b690f9d28",
    
  9. If the loan is Closed with “repayment”, the outcome child JSON node will be repayment and a collateral_repayment_txid will be present. If this is true, we assume the test was successful.

Once you have finished this challenge, please return any sats received from the faucet to this address: tb1qd8cg49sy99cln5tq2tpdm7xs4p9s5v6le4jx4c

Bonus:

Save the test results to a DB and make them accessible through the server interface

Notes: If anything goes differently than expected or described in this page, make a note of it and try to handle it the best as you can.