2019-07-31 15:37:00 +00:00
|
|
|
package actors_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
cbor "github.com/ipfs/go-ipld-cbor"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/go-lotus/chain/actors"
|
|
|
|
"github.com/filecoin-project/go-lotus/chain/address"
|
|
|
|
"github.com/filecoin-project/go-lotus/chain/types"
|
|
|
|
"github.com/filecoin-project/go-lotus/chain/vm"
|
|
|
|
)
|
|
|
|
|
|
|
|
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-07-31 15:37:00 +00:00
|
|
|
ret, _ := h.CreateActor(t, creatorAddr, actors.MultisigActorCodeCid,
|
|
|
|
actors.MultiSigConstructorParams{
|
|
|
|
Signers: []address.Address{creatorAddr, sig1Addr, sig2Addr},
|
|
|
|
Required: 2,
|
|
|
|
})
|
|
|
|
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-07-31 15:37:00 +00:00
|
|
|
HarnessActor(&multSigAddr, &creatorAddr, actors.MultisigActorCodeCid,
|
|
|
|
func() interface{} {
|
|
|
|
return actors.MultiSigConstructorParams{
|
|
|
|
Signers: []address.Address{creatorAddr, sig1Addr, sig2Addr},
|
|
|
|
Required: 2,
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
|
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
|
2019-07-31 15:37:00 +00:00
|
|
|
ret, _ := h.Invoke(t, creatorAddr, multSigAddr, actors.MultiSigMethods.Propose,
|
2019-08-15 16:23:28 +00:00
|
|
|
|
2019-07-31 15:37:00 +00:00
|
|
|
actors.MultiSigProposeParams{
|
|
|
|
To: outsideAddr,
|
2019-08-21 20:47:13 +00:00
|
|
|
Value: types.NewInt(sendVal),
|
2019-07-31 15:37:00 +00:00
|
|
|
})
|
|
|
|
ApplyOK(t, ret)
|
2019-07-31 17:30:08 +00:00
|
|
|
var txIDParam actors.MultiSigTxID
|
|
|
|
err := cbor.DecodeInto(ret.Return, &txIDParam.TxID)
|
2019-07-31 15:37:00 +00:00
|
|
|
assert.NoError(t, err, "decoding txid")
|
2019-08-04 12:11:06 +00:00
|
|
|
|
|
|
|
ret, _ = h.Invoke(t, outsideAddr, multSigAddr, actors.MultiSigMethods.Approve,
|
|
|
|
txIDParam)
|
|
|
|
assert.Equal(t, uint8(1), 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
|
|
|
|
2019-08-21 20:47:13 +00:00
|
|
|
ret2, _ := h.Invoke(t, sig1Addr, multSigAddr, actors.MultiSigMethods.Approve,
|
2019-07-31 17:30:08 +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
|
|
|
}
|
|
|
|
|
|
|
|
}
|