Fix MTransaction
License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
This commit is contained in:
parent
f19b8c82f4
commit
8e4661e6d2
@ -17,6 +17,7 @@ func init() {
|
|||||||
cbor.RegisterCborType(MultiSigSigner{})
|
cbor.RegisterCborType(MultiSigSigner{})
|
||||||
cbor.RegisterCborType(MultiSigSwapSignerParams{})
|
cbor.RegisterCborType(MultiSigSwapSignerParams{})
|
||||||
cbor.RegisterCborType(MultiSigChangeReqParams{})
|
cbor.RegisterCborType(MultiSigChangeReqParams{})
|
||||||
|
cbor.RegisterCborType(MTransaction{})
|
||||||
}
|
}
|
||||||
|
|
||||||
type MultiSigActor struct{}
|
type MultiSigActor struct{}
|
||||||
|
@ -1,15 +1,18 @@
|
|||||||
package actors_test
|
package actors_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
cbor "github.com/ipfs/go-ipld-cbor"
|
cbor "github.com/ipfs/go-ipld-cbor"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"go.opencensus.io/trace"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-lotus/chain/actors"
|
"github.com/filecoin-project/go-lotus/chain/actors"
|
||||||
"github.com/filecoin-project/go-lotus/chain/address"
|
"github.com/filecoin-project/go-lotus/chain/address"
|
||||||
"github.com/filecoin-project/go-lotus/chain/types"
|
"github.com/filecoin-project/go-lotus/chain/types"
|
||||||
"github.com/filecoin-project/go-lotus/chain/vm"
|
"github.com/filecoin-project/go-lotus/chain/vm"
|
||||||
|
"github.com/filecoin-project/go-lotus/tracing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMultiSigCreate(t *testing.T) {
|
func TestMultiSigCreate(t *testing.T) {
|
||||||
@ -38,9 +41,15 @@ func ApplyOK(t testing.TB, ret *vm.ApplyRet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMultiSigOps(t *testing.T) {
|
func TestMultiSigOps(t *testing.T) {
|
||||||
|
je := tracing.SetupJaegerTracing("test")
|
||||||
|
defer je.Flush()
|
||||||
|
ctx, span := trace.StartSpan(context.Background(), "/test-"+t.Name())
|
||||||
|
defer span.End()
|
||||||
|
|
||||||
var creatorAddr, sig1Addr, sig2Addr, outsideAddr address.Address
|
var creatorAddr, sig1Addr, sig2Addr, outsideAddr address.Address
|
||||||
var multSigAddr address.Address
|
var multSigAddr address.Address
|
||||||
opts := []HarnessOpt{
|
opts := []HarnessOpt{
|
||||||
|
HarnessCtx(ctx),
|
||||||
HarnessAddr(&creatorAddr, 10000),
|
HarnessAddr(&creatorAddr, 10000),
|
||||||
HarnessAddr(&sig1Addr, 10000),
|
HarnessAddr(&sig1Addr, 10000),
|
||||||
HarnessAddr(&sig2Addr, 10000),
|
HarnessAddr(&sig2Addr, 10000),
|
||||||
@ -54,14 +63,14 @@ func TestMultiSigOps(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
curVal := types.NewInt(2000)
|
||||||
h := NewHarness2(t, opts...)
|
h := NewHarness2(t, opts...)
|
||||||
{
|
{
|
||||||
sendVal := types.NewInt(2000)
|
ret, state := h.SendFunds(t, creatorAddr, multSigAddr, curVal)
|
||||||
ret, state := h.SendFunds(t, creatorAddr, multSigAddr, sendVal)
|
|
||||||
ApplyOK(t, ret)
|
ApplyOK(t, ret)
|
||||||
ms, err := state.GetActor(multSigAddr)
|
ms, err := state.GetActor(multSigAddr)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, sendVal, ms.Balance)
|
assert.Equal(t, curVal, ms.Balance)
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -72,9 +81,21 @@ func TestMultiSigOps(t *testing.T) {
|
|||||||
Value: sendVal,
|
Value: sendVal,
|
||||||
})
|
})
|
||||||
ApplyOK(t, ret)
|
ApplyOK(t, ret)
|
||||||
var txIdParam actors.MultiSigTxID
|
var txIDParam actors.MultiSigTxID
|
||||||
err := cbor.DecodeInto(ret.Return, &txIdParam.TxID)
|
err := cbor.DecodeInto(ret.Return, &txIDParam.TxID)
|
||||||
assert.NoError(t, err, "decoding txid")
|
assert.NoError(t, err, "decoding txid")
|
||||||
|
ret, state := h.Invoke(t, sig1Addr, multSigAddr, actors.MultiSigMethods.Approve,
|
||||||
|
txIDParam)
|
||||||
|
ApplyOK(t, ret)
|
||||||
|
curVal = types.BigSub(curVal, sendVal)
|
||||||
|
|
||||||
|
outAct, err := state.GetActor(outsideAddr)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, sendVal, outAct.Balance)
|
||||||
|
|
||||||
|
msAct, err := state.GetActor(multSigAddr)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, curVal, msAct.Balance)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -41,9 +41,10 @@ type Harness2 struct {
|
|||||||
Stage HarnessStage
|
Stage HarnessStage
|
||||||
Nonces map[address.Address]uint64
|
Nonces map[address.Address]uint64
|
||||||
|
|
||||||
bs blockstore.Blockstore
|
ctx context.Context
|
||||||
vm *vm.VM
|
bs blockstore.Blockstore
|
||||||
cs *store.ChainStore
|
vm *vm.VM
|
||||||
|
cs *store.ChainStore
|
||||||
}
|
}
|
||||||
|
|
||||||
var HarnessMinerFunds = types.NewInt(1000000)
|
var HarnessMinerFunds = types.NewInt(1000000)
|
||||||
@ -99,20 +100,28 @@ func HarnessActor(actor *address.Address, creator *address.Address, code cid.Cid
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func HarnessCtx(ctx context.Context) HarnessOpt {
|
||||||
|
return func(t testing.TB, h *Harness2) error {
|
||||||
|
h.ctx = ctx
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func NewHarness2(t *testing.T, options ...HarnessOpt) *Harness2 {
|
func NewHarness2(t *testing.T, options ...HarnessOpt) *Harness2 {
|
||||||
h := &Harness2{
|
h := &Harness2{
|
||||||
Stage: HarnessPreInit,
|
Stage: HarnessPreInit,
|
||||||
Nonces: make(map[address.Address]uint64),
|
Nonces: make(map[address.Address]uint64),
|
||||||
}
|
HI: HarnessInit{
|
||||||
h.bs = bstore.NewBlockstore(dstore.NewMapDatastore())
|
NAddrs: 1,
|
||||||
h.HI = HarnessInit{
|
Miner: blsaddr(0),
|
||||||
NAddrs: 1,
|
Addrs: map[address.Address]types.BigInt{
|
||||||
Miner: blsaddr(0),
|
blsaddr(0): HarnessMinerFunds,
|
||||||
Addrs: map[address.Address]types.BigInt{
|
},
|
||||||
blsaddr(0): HarnessMinerFunds,
|
|
||||||
},
|
},
|
||||||
}
|
|
||||||
|
|
||||||
|
ctx: context.Background(),
|
||||||
|
bs: bstore.NewBlockstore(dstore.NewMapDatastore()),
|
||||||
|
}
|
||||||
for _, opt := range options {
|
for _, opt := range options {
|
||||||
err := opt(t, h)
|
err := opt(t, h)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -152,7 +161,7 @@ func (h *Harness2) Apply(t testing.TB, msg types.Message) (*vm.ApplyRet, *state.
|
|||||||
h.Nonces[msg.From] = msg.Nonce + 1
|
h.Nonces[msg.From] = msg.Nonce + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
ret, err := h.vm.ApplyMessage(context.TODO(), &msg)
|
ret, err := h.vm.ApplyMessage(h.ctx, &msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Applying message: %+v", err)
|
t.Fatalf("Applying message: %+v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user