Git Product home page Git Product logo

algoapp_method_unittest's Introduction

AlgoApp Method Unit Test

The algoapp_method_unittest utility library is a support to perform unit tests on Algorand App's methods call, verifying their expected behaviour.

  • Approval Unit Test: testing a method call expecting App's approval.
  • Rejection Unit Test: testing a method call expecting App's rejection.

Dependencies:

Building Unit Tests

Let's test the following ASA State Observer method:

{
  "name": "AsaAmountEq",
  "desc": "Asserts that the targetAccount owns an amount of targetAsa equal to amt",
  "args": [
    { "name": "amt", "type": "uint64", "desc": "Asset amount" }
  ],
  "accounts" : [
    { "name": "targetAccount" }
  ],
  "foreign-assets" : [
    { "name": "targetAsa" }
  ]
}

Precondition: targetAccount owns an amt of targetAsa equal to 1.

Given the previous precondition, we can build a proper App's method call, expecting an Approval as App's behaviour, and run an Approval Unit Test against it:

approval_unit_test(
    algod_client,
    test_stats,
    call_asa_state_observer(
        method=METHOD_ASA_AMOUNT_EQ,
        caller=deployer,
        app_id=asa_state_observer_id,
        target_asa_id=test_asa_id,
        target_account=deployer,
        amount=1
    )
)

Unit Tests result example

The algoapp_method_unittest has been used in this example to perform unit tests against all ASA State Observer app's methods behaviour.

ASA State Observer Unit Tests example output

Method: AsaOptedIn		Expected ASC1 behaviour: Approval
Transaction CCF6IGELZMQBGFT6CX62OFOBZX24RFIYGG4RHBLPWI6O4TX72QJA confirmed in round 246.
✅️ Passed! Transaction(s) approved as expected.

Method: AsaAmountEq		Expected ASC1 behaviour: Approval
Transaction LKHN777YXLALWBYDCGSLXWCXHEXAXONM6ZSD27A2SRYWJUFYQRAA confirmed in round 247.
✅️ Passed! Transaction(s) approved as expected.

Method: AsaAmountGt		Expected ASC1 behaviour: Approval
Transaction MRGZIUEKCBTS2RWYYSWDJY27AOTM3EEYINCNHE7BF5JFW5RSIRSQ confirmed in round 248.
✅️ Passed! Transaction(s) approved as expected.

Method: AsaAmountGe		Expected ASC1 behaviour: Approval
Transaction WQ64ICMCQGEUZO6AC37PE2SYGUVNBFCDDHULAA755F7WOE4BKZKA confirmed in round 249.
✅️ Passed! Transaction(s) approved as expected.

Method: AsaAmountGe		Expected ASC1 behaviour: Approval
Transaction 3JYB3VJJ3FJZYTB2KFER4CDVUGIZJCD73B5VXVCTEKCRF3QK64HQ confirmed in round 250.
✅️ Passed! Transaction(s) approved as expected.

Method: AsaAmountLt		Expected ASC1 behaviour: Approval
Transaction EQ6AWKFLIAG45XQAY35JIUFWB6V3SHNJE642YVKGMFKDZOEYPP2Q confirmed in round 251.
✅️ Passed! Transaction(s) approved as expected.

Method: AsaAmountLe		Expected ASC1 behaviour: Approval
Transaction W5FIXUY5GTBFRNOJKVRMKM6TTGMS22EOLGR2YXPISWEO5A2E3EGQ confirmed in round 252.
✅️ Passed! Transaction(s) approved as expected.

Method: AsaAmountLe		Expected ASC1 behaviour: Approval
Transaction D5OXQFNDHVWFLKADUVL5KL3WJV56PHLEPARLDJ5PU3YQW3RC7WPA confirmed in round 253.
✅️ Passed! Transaction(s) approved as expected.

Method: AsaOptedIn		Expected ASC1 behaviour: Rejection
✅️ Passed! Transaction(s) rejected as expected.

Method: AsaAmountEq		Expected ASC1 behaviour: Rejection
✅️ Passed! Transaction(s) rejected as expected.

Method: AsaAmountGt		Expected ASC1 behaviour: Rejection
✅️ Passed! Transaction(s) rejected as expected.

Method: AsaAmountGe		Expected ASC1 behaviour: Rejection
✅️ Passed! Transaction(s) rejected as expected.

Method: AsaAmountLt		Expected ASC1 behaviour: Rejection
✅️ Passed! Transaction(s) rejected as expected.

Method: AsaAmountLe		Expected ASC1 behaviour: Rejection
✅️ Passed! Transaction(s) rejected as expected.

📊 Test Stats
Approval Unit Tests: 8
Rejection Unit Tests: 6
Passed: 14
Failed: 0

Tips

Use the app_method_unittest library with the Sandbox in devMode to speed up the testing process.

algoapp_method_unittest's People

Contributors

cusma avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

emg110 bmscis

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.