@baseUrl = http://localhost:8080
@descriptor = wpkh([a1b2c3d4/84h/0h/0h]xpub6CatWdiZynkCminahu8Gmr7FAVnQXBTSMaBxn6qmBNkdm9tDkFzWmjmDrLBCQSTa7BHgpEjCXzMTCyDsQLSmcGYJHBB7cTwpqLNRKGP47uw/0/*)#qwer1234

### Analyze wallet
# @name analyze
POST {{baseUrl}}/api/wallet/analyze
Content-Type: application/json

{
  "descriptor": "{{descriptor}}"
}

> {%
  client.test("status is 200", function() {
    client.assert(response.status === 200, "expected 200");
  });
  client.test("response has analysisId", function() {
    client.assert(typeof response.body.analysisId === "string", "expected analysisId string");
    client.assert(response.body.analysisId.length > 0, "expected non-empty analysisId");
  });
%}

### Get UTXOs
GET {{baseUrl}}/api/wallet/{{analyze.response.body.$.analysisId}}/utxos

### Scan descriptor
# @name scan
GET {{baseUrl}}/api/wallet/scan?descriptor={{descriptor}}

> {%
  client.test("status is 200", function() {
    client.assert(response.status === 200, "expected 200");
  });
  client.test("response has descriptor", function() {
    client.assert(typeof response.body.descriptor === "string", "expected descriptor string");
  });
  client.test("summary totals are correct", function() {
    client.assert(response.body.summary.total === 5, "expected 5 utxos");
    client.assert(response.body.summary.clean === 1, "expected 1 clean");
    client.assert(response.body.summary.vulnerable === 4, "expected 4 vulnerable");
  });
  client.test("utxos array has 5 items", function() {
    client.assert(response.body.utxos.length === 5, "expected 5 utxos in array");
  });
  client.test("each utxo has required fields", function() {
    response.body.utxos.forEach(function(utxo) {
      client.assert(typeof utxo.txid === "string", "expected txid");
      client.assert(typeof utxo.address === "string", "expected address");
      client.assert(typeof utxo.amountBtc === "number", "expected amountBtc");
      client.assert(Array.isArray(utxo.vulnerabilities), "expected vulnerabilities array");
    });
  });
%}
