#Algorand TypeScript Testing v1.0.1 breaking changes

23 messages · Page 1 of 1 (latest)

sour jolt
#

I am in the process updating one of my projects (https://github.com/bwmx/randomness-beacon/tree/upgrade-puya-ts) to the latest puya-ts version. Everything has went well and it was relatively painless (migration guide useful, but still certainly missing a few useful bits of info about structs/types).

Now everything builds, and the output is as expected. My e2e tests against localnet all pass successfully, but the algorand-typescript-testing tests fail:

Unknown contract: smart_contracts/randomness_beacon/contract.algo.ts::RandomnessBeacon

contract.algo.spec.ts:166 contracts/example-caller.algo.ts cannot complete arc4.abiCall even when running in algorand-typescript-testing environment correctly with ApplicationSpy hooked methods.

You can read more here: https://github.com/algorandfoundation/algorand-typescript-testing/blob/33ed9bd80ac1db11c35ef685e29078663bc7ee0c/docs/tg-application-spy.md#L5

In previous versions of puya-ts, these tests would have passed no problem, but now it seems like created/emulated applications in the emulated ledger are inaccessible to calling apps.

I don’t think any of us have much experience with this library, but although e2e tests are sufficient, quick unit tests of course make the experience much better, but beyond testing basic apps we need to use this ApplicationSpy class to properly catch/mock other app calls.

If anyone wants to take a look, you can quickly replicate by doing below (to clone my repo and test it):

git clone -b upgrade-puya-ts https://github.com/bwmx/randomness-beacon
cd projects/randomness-beacon && npm install
npm run test

You will see the can call createRequest test will fail as described above. If anyone has any ideas or experience please do share. It would be good to get some dialogue with the dev team behind it, I feel like whatever issues are going on could be fixed easily (anything outside the basics is a battle, or maybe I'm using it with the wrong intents)

GitHub

A callback based randomness (based on VRF) beacon for Algorand. Work in progress. - GitHub - bwmx/randomness-beacon at upgrade-puya-ts

GitHub

Contribute to algorandfoundation/algorand-typescript-testing development by creating an account on GitHub.

sour jolt
#

Algorand TypeScript Testing v1.0.1 breaking changes

foggy galleon
#

Thank you for the details. I am having a look.

foggy galleon
#

It looks like @contract decorator applied to RandomnessBeacon contract is causing some conflicts in the testing library code. I will look into it more to see why the decorator is causing the error. In the mean time, if we remove the decorator, we will no longer seeunkown contracterror. I noticed thenameproperty has the same value as class name so it can be omitted. IfavmVerisondoes not have to be pinned at11, we can drop it as well. avmVersion` will default to current mainnet version.

sour jolt
low willowBOT
#

Gave +1 Rep to @foggy galleon (current: #103 - 1)

foggy galleon
#

Yes. That's me, boblat with MakerX. Explicitly declaring those properties in the decorator should be fine. I've pushed up a PR which should fix unknown contract error for the decorated contracts. Thank you for bringing it to our attention.
https://github.com/algorandfoundation/algorand-typescript-testing/pull/108

GitHub

do not use .prototype.constructor.name which can be changed during transpilation as per this commit in esbuild
capture ClassDeclaration.name as contract name instead

sour jolt
#

Having some issues with ApplicationSpy seems more than 1 callback/hook, only the first one actually gets called (despite being initialised and 2 abi functions hooked). This has also existed in previous versions (but I just gave up and forgot).

requestId and round are returned by the ExampleContract.test1() method which internally calls RandomnessBeacon.createRequest() and then returns the ID, and round where the randomness request can be fulfilled.

beaconContract.completeRequest(requestId, proof.buffer as any as VrfProof)

I get the error Block 2480589172698743110 not set (this changes every test run, almost like its reading random data from memory/positions and not the params), when I follow the stack it’s not even calling the hook specified in the earlier ApplicationSpy instance. See spy.on.createRequest for an example that already works (and passes in previous tests). Also the requested block is 7 and is being passed as uint64 value so hmm

My intention is to hook the completeRequest() function so I can simulate a vrf_verify op (since we don’t have this available in the emulated environment). The hook never gets calls, see my simple console.log…

Any ideas what’s going on here? (Why my hooked completeRequest isn’t getting called?) Again this can be replicated by cloning my repo (I just pushed some changes with the test uncommented, e2e works full as reference so you can see my intention).

#
git clone -b upgrade-puya-ts https://github.com/bwmx/randomness-beacon
foggy galleon
#

The hooks set up in ApplicationSpy are only triggered for internal transactions (contract to contract calls). They are not triggered when the contract method is directly called from the test code, e.g. beaconContract.completeRequest(requestId, proof.buffer as any as VrfProof).

If we are trying to mock vrfVerify, we can just use standard mocking library. An example can be found here.

Please let me know if it does not meet your requirement.

GitHub

Contribute to algorandfoundation/algorand-typescript-testing development by creating an account on GitHub.

sour jolt
# foggy galleon The hooks set up in `ApplicationSpy` are only triggered for internal transaction...

Thanks, really appreciating your help. Yes that is true about the vrf mock, I updated the branch to properly mock it (and removing the .on.completeRequest callback) and eliminate any other possible sources of error. I still get the same output error at const blockSeed = op.Block.blkSeed(request.round) where a very large (incorrect block) is trying to be accessed. https://github.com/bwmx/randomness-beacon/blob/upgrade-puya-ts/projects/randomness-beacon/smart_contracts/randomness_beacon/contract.algo.ts#L297 is reference, but I know the code is correct, the e2e test passes. Easily replicated as once before.

GitHub

A callback based randomness (based on VRF) beacon for Algorand. Work in progress. - bwmx/randomness-beacon

low willowBOT
#

Gave +1 Rep to @foggy galleon (current: #70 - 2)

sour jolt
#

As described in my earlier comment, the round in the accessed request type is 7 as uint64 (confirmed), I hope I've given enough information, thanks in advance for any insight. If there's anything else I can do to help, let me know. (of course I know this behaviour works against a real network, but I hope to understand some of these more complex test cases and constraints)

foggy galleon
#

Thank you for the info. I will look into it tomorrow. By the way, the fix for unknown contractor error is now available in 1.0.2-beta.1.

foggy galleon
#

I found that clone was returning a different value than the original when properties are defined in a different order than the type declaration. I've pushed up a PR to fix that. In the mean time, if you line up the properties with type declaration, the test would pass, e.g.

const request: RandomnessRequest = {
  createdAt: Global.round,
  requesterAppId: exampleCallerAppId,
  requesterAddress: requesterAddress,
  round: round,
  costs: {
    fees: feesPaid,
    boxMbr: boxMbr,
  },
}
GitHub

clone was returning different value for an object with a type definition if the properties are in different order than the type definition

type Obj = {
a: uint64
b: boolean
c: string
}
const...

sour jolt
low willowBOT
#

Gave +1 Rep to @foggy galleon (current: #56 - 3)

foggy galleon
nocturne latch
#

Hello everyone Please I am working on a smart contract and this error was developed on testing any idea the possible cause and available solution: Network request error. Received status 400 (): TransactionPool.Remember: transaction X5FZRJDVQ6KSHHRYEHF5IKEGEWV4ICDTBQI5DC3UKGAZR5SKGOKA: transaction rejected by ApprovalProgram. Aborting payment

nocturne latch