2019-07-31 15:37:00 +00:00
|
|
|
package actors_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-02-06 19:49:21 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/actors/builtin"
|
|
|
|
samsig "github.com/filecoin-project/specs-actors/actors/builtin/multisig"
|
2019-07-31 15:37:00 +00:00
|
|
|
cbor "github.com/ipfs/go-ipld-cbor"
|
|
|
|
"github.com/stretchr/testify/assert"
|
2019-09-10 23:03:17 +00:00
|
|
|
cbg "github.com/whyrusleeping/cbor-gen"
|
2019-07-31 15:37:00 +00:00
|
|
|
|
2019-12-19 20:13:17 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
"github.com/filecoin-project/lotus/chain/vm"
|
2020-01-22 23:02:17 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/specs-actors/actors/abi/big"
|
2019-07-31 15:37:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMultiSigCreate(t *testing.T) {
|
|
|
|
var creatorAddr, sig1Addr, sig2Addr, outsideAddr address.Address
|
|
|
|
opts := []HarnessOpt{
|
2019-08-29 18:20:59 +00:00
|
|
|
HarnessAddr(&creatorAddr, 100000),
|
|
|
|
HarnessAddr(&sig1Addr, 100000),
|
|
|
|
HarnessAddr(&sig2Addr, 100000),
|
|
|
|
HarnessAddr(&outsideAddr, 100000),
|
2019-07-31 15:37:00 +00:00
|
|
|
}
|
|
|
|
|
2019-08-29 18:20:59 +00:00
|
|
|
h := NewHarness(t, opts...)
|
2019-10-21 18:12:11 +00:00
|
|
|
ret, _ := h.CreateActor(t, creatorAddr, actors.MultisigCodeCid,
|
2020-02-06 19:49:21 +00:00
|
|
|
&samsig.ConstructorParams{
|
2020-01-22 23:02:17 +00:00
|
|
|
Signers: []address.Address{creatorAddr, sig1Addr, sig2Addr},
|
|
|
|
NumApprovalsThreshold: 2,
|
2019-07-31 15:37:00 +00:00
|
|
|
})
|
|
|
|
ApplyOK(t, ret)
|
|
|
|
}
|
|
|
|
|
|
|
|
func ApplyOK(t testing.TB, ret *vm.ApplyRet) {
|
|
|
|
t.Helper()
|
|
|
|
if ret.ExitCode != 0 {
|
|
|
|
t.Fatalf("exit code should be 0, got %d, actorErr: %+v", ret.ExitCode, ret.ActorErr)
|
|
|
|
}
|
2019-08-09 21:41:50 +00:00
|
|
|
if ret.ActorErr != nil {
|
|
|
|
t.Fatalf("somehow got an error with exit == 0: %s", ret.ActorErr)
|
|
|
|
}
|
2019-07-31 15:37:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestMultiSigOps(t *testing.T) {
|
|
|
|
var creatorAddr, sig1Addr, sig2Addr, outsideAddr address.Address
|
|
|
|
var multSigAddr address.Address
|
|
|
|
opts := []HarnessOpt{
|
2019-08-15 16:23:28 +00:00
|
|
|
HarnessAddr(&creatorAddr, 100000),
|
|
|
|
HarnessAddr(&sig1Addr, 100000),
|
|
|
|
HarnessAddr(&sig2Addr, 100000),
|
2019-08-29 18:20:59 +00:00
|
|
|
HarnessAddr(&outsideAddr, 100000),
|
2019-10-21 18:12:11 +00:00
|
|
|
HarnessActor(&multSigAddr, &creatorAddr, actors.MultisigCodeCid,
|
2019-09-10 23:03:17 +00:00
|
|
|
func() cbg.CBORMarshaler {
|
2020-02-06 19:49:21 +00:00
|
|
|
return &samsig.ConstructorParams{
|
2020-01-22 23:02:17 +00:00
|
|
|
Signers: []address.Address{creatorAddr, sig1Addr, sig2Addr},
|
|
|
|
NumApprovalsThreshold: 2,
|
2019-07-31 15:37:00 +00:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
|
2019-08-29 18:20:59 +00:00
|
|
|
h := NewHarness(t, opts...)
|
2019-07-31 15:37:00 +00:00
|
|
|
{
|
2019-08-21 20:47:13 +00:00
|
|
|
const chargeVal = 2000
|
2019-08-04 12:11:06 +00:00
|
|
|
// Send funds into the multisig
|
2019-08-21 20:47:13 +00:00
|
|
|
ret, _ := h.SendFunds(t, creatorAddr, multSigAddr, types.NewInt(chargeVal))
|
2019-07-31 15:37:00 +00:00
|
|
|
ApplyOK(t, ret)
|
2019-08-21 20:47:13 +00:00
|
|
|
h.AssertBalanceChange(t, creatorAddr, -chargeVal)
|
|
|
|
h.AssertBalanceChange(t, multSigAddr, chargeVal)
|
2019-07-31 15:37:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2019-08-04 12:11:06 +00:00
|
|
|
// Transfer funds outside of multsig
|
2019-08-21 20:47:13 +00:00
|
|
|
const sendVal = 1000
|
2020-02-06 19:49:21 +00:00
|
|
|
ret, _ := h.Invoke(t, creatorAddr, multSigAddr, uint64(builtin.MethodsMultisig.Propose),
|
|
|
|
&samsig.ProposeParams{
|
2019-07-31 15:37:00 +00:00
|
|
|
To: outsideAddr,
|
2020-01-22 23:02:17 +00:00
|
|
|
Value: big.NewInt(sendVal),
|
2019-07-31 15:37:00 +00:00
|
|
|
})
|
|
|
|
ApplyOK(t, ret)
|
2020-02-06 19:49:21 +00:00
|
|
|
var txIDParam samsig.TxnIDParams
|
2020-01-22 23:02:17 +00:00
|
|
|
err := cbor.DecodeInto(ret.Return, &txIDParam.ID)
|
2019-07-31 15:37:00 +00:00
|
|
|
assert.NoError(t, err, "decoding txid")
|
2019-08-04 12:11:06 +00:00
|
|
|
|
2020-02-06 19:49:21 +00:00
|
|
|
ret, _ = h.Invoke(t, outsideAddr, multSigAddr, uint64(builtin.MethodsMultisig.Approve),
|
2019-09-10 23:03:17 +00:00
|
|
|
&txIDParam)
|
2020-01-23 23:35:41 +00:00
|
|
|
assert.Equal(t, uint8(18), ret.ExitCode, "outsideAddr should not approve")
|
2019-08-21 20:47:13 +00:00
|
|
|
h.AssertBalanceChange(t, multSigAddr, 0)
|
2019-08-04 12:11:06 +00:00
|
|
|
|
2020-02-06 19:49:21 +00:00
|
|
|
ret2, _ := h.Invoke(t, sig1Addr, multSigAddr, uint64(builtin.MethodsMultisig.Approve),
|
2019-09-10 23:03:17 +00:00
|
|
|
&txIDParam)
|
2019-08-15 16:23:28 +00:00
|
|
|
ApplyOK(t, ret2)
|
2019-07-31 17:30:08 +00:00
|
|
|
|
2019-08-21 20:47:13 +00:00
|
|
|
h.AssertBalanceChange(t, outsideAddr, sendVal)
|
|
|
|
h.AssertBalanceChange(t, multSigAddr, -sendVal)
|
2019-07-31 15:37:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|