interbtc-api icon indicating copy to clipboard operation
interbtc-api copied to clipboard

Refactor lib tests to use dryRun to avoid changing state

Open bvotteler opened this issue 3 years ago • 0 comments

We should be able to refactor some of our integration tests to use dryRun where the tests do not rely on a changed state for follow up actions.

The approach below can be used to check the success of a transaction without modifying the state of the blockchain

let request_redeem = api.tx.redeem.requestRedeem(2000, {P2WPKHv0: '0x01197bcaf42e278fcca2b55275cd64b25d240e7c'}, vault_id);
    const transactionAPI = new DefaultTransactionAPI(api, userKeyring);
    
    let myNonce = await api.rpc.system.accountNextIndex(userKeyring.address);
    const signed = request_redeem.sign(userKeyring, { nonce:  myNonce});

    const result = await signed.dryRun(transactionAPI.getAccount()!);
    
    // A technically valid but failing transaction returns Ok(Err(...))
    const resultOk = result.isOk && result.asOk.isOk;

    console.log("isOk", resultOk);

bvotteler avatar Dec 21 '22 11:12 bvotteler