Motoko - Adding system capability to an inline function

All my beautiful mops tests are bloody. :a: :b: :ab: :o2: :drop_of_blood:

How can I add a system function to an inline function? I’ve tried sticking system just about everywhere.

set_nfts needs system capabilities.

I ended up having to go into @ZenVoich test module and add a specific system test:

       public func testsys<system>(name : Text, fn : <system>() -> ()) {
		Debug.print("mops:1:start " # name);
		fn<system>();
		Debug.print("mops:1:end " # name);
	};

No clue if this is the best solution.

1 Like

That sounds like reasonable solution. Sorry for the hassle.

@ZenVoich Does this seem like a reasonable thing to add to the test component? I sent a pull request. There maybe some other places it is needed, but I don’t know the library well. Maybe a test is needed also?

It also gets funky around Map functions. Maybe most collection functions need to add a mapsys that has system capabilities?

image

Currently, I’m having to go rewrite all this as for loops.

Thanks. I added tests and stuff… Published 2.0.0

2 Likes

I feel your pain, though I guess code that maps async function needs a similar rewrite.

Maybe we could provide:

addCyclesCap : <system>() -> (Nat-> ());

Which, provided you already have system capability, gives you a function that you can call without system capability, to use from other callsites, e.g. arguments to map.

Would need to think about that and if it doesn’t undermine everything else.

You’d probably still need to rewrite your set_nfts<system>(...) function to something like set_nfts(cap, ...) where `let cap = addCyclesCap()’ is defined earlier on somewhere (but where?).