-
Notifications
You must be signed in to change notification settings - Fork 27
Test current balance behaviour in recursive sends #52
Comments
@anorth are these questions about which behaviour is correct (which would need to be discussed in the team)? Or are these test scenarios worded as questions? |
I've removed the question marks - they reflect expected behaviour to be tested. |
@willscott We'll need the chaos actor to test this. Suggestion: add a
|
Sends from an actor to itself are a whole extra class additional to what I described originally, which should definitely be included. For a self-send with value, I would expect the observed balance to not change because it is subtracted and then added to the same actor. To test the balance changes originally described, you'll need at least two instances of the chaos actor, one sending to the other. |
@anorth Gotcha. In the reflexive send scenario, wouldn't we expect the balance to have been deducted gas, though? |
Based on @anorth's feedback, the way we would do this is by using
type AddressSend struct {
Address address.Address
Value abi.TokenAmount
}
type AddressBalance struct {
Address address.Address
Before, After abi.TokenAmount
}
func (a *ChaosActor) RecursiveSend(rt *Runtime, sends []*AddressSend) (balances []*AddressBalance) {
rt.ValidateImmediateCallerAcceptAny()
// We're the last one in the chain.
if len(sends) == 0 {
return []*AddressBalance{&AddressBalance{
Address: rt.Message().Receiver(),
Before: rt.CurrentBalance(),
After: rt.CurrentBalance(),
}}
}
before := rt.CurrentBalance()
// next is the chaos actor address we are routing to, xs is the parameters we'll be sending it.
next, xs := sends[0], sends[1:]
res, err := rt.Send(next.Address, MethodRecursiveSend, xs, next.Value)
if !err.IsSuccess() {
panic(err)
}
// assume res is already []*AddressBalance; in practice you'll need to call res.Into() to deserialise
after := rt.CurrentBalance()
// prepend our readings to the incoming slice, and return.
ret := append([]*AddressBalance{&AddressBalance{
Address: rt.Message().Receiver(),
Before: before,
After: after,
}}, res...)
return ret
} |
Value covering the entire gas limit for a top-level message is deducted from the sender before the message is processed, and any un-used refunded right at the end. So whatever the observed balance is inside a top level call to actor A, if it sends value to itself then inside the nested call I expect the observed balance to be the same; all the gas was already handled before the top-level call started. |
@raulk I knocked up this PoC while trying to work out how to create multiple chaos actors: #155 I'm trying to avoid using the chaos I looked into using the init actor to create a chaos actor but it is heavily restricted in what it can create and which actors are allowed to create. So in #155 I'm using
This looks really succinct and I'd be happy to switch to using it because the message construction code in #155 is a little mind bending. That said, I was trying to avoid adding even more functionality to the chaos actor - we've always said chaos should be primitives and this would be very specific to this test scenario...and I'm not certain it has high potential to be used in other tests that aren't just derivatives of this one. WDYT? |
Actor A invokes a method on Actor B and supplies a nonzero value. Before Actor B’s execution is complete, it invokes a method on Actor A, but does NOT supply value. Within this context, CurrentBalance should factor in the amount initially sent to Actor B.
Finally, Actor B’s execution finishes successfully and Actor A continues execution where it left off. CurrentBalance should factor in the amount sent to Actor B.
Via @wadealexc
The text was updated successfully, but these errors were encountered: