Skip to content

Commit

Permalink
Fix UnmarshalTLB for ExtOutMsgBody, InMsgBody
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksej-paschenko committed Feb 13, 2024
1 parent bcc77d4 commit d0953a7
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 8 deletions.
60 changes: 52 additions & 8 deletions abi/generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,45 @@ func TestDecodeExternalIn(t *testing.T) {
return b
},
},
{
name: "unknown op",
boc: "b5ee9c7201010201006d00019a6aca8192dee134cc67db935e39d6fa04c0e6f28e895902c8b28af7d7900599e6e785f48f37d72a0a1709affe618c747cd9339246c2aefc57f34e31951eb8e309000000305ea5f8c500000006a0010036c4402468acf000000000000000000000000000000000626c617374",
interfaces: []ContractInterface{WalletV3R1},
wantOpName: "WalletSignedV3",
wantValue: func() any {
b := WalletSignedV3ExtInMsgBody{
SubwalletId: 48,
ValidUntil: 1587935429,
Seqno: 6,
Payload: WalletV1ToV4Payload{
{
Mode: 160,
Message: MessageRelaxed{
SumType: "MessageExtOut",
},
},
},
}
sig, _ := hex.DecodeString("6aca8192dee134cc67db935e39d6fa04c0e6f28e895902c8b28af7d7900599e6e785f48f37d72a0a1709affe618c747cd9339246c2aefc57f34e31951eb8e309")
copy(b.Signature[:], sig)
b.Payload[0].Message.MessageExtOut.Src.SumType = "AddrNone"
var addr tlb.MsgAddress
if err := json.Unmarshal([]byte("12345678"), &addr); err != nil {
t.Fatalf("can't unmarshal address: %v", err)
}
b.Payload[0].Message.MessageExtOut.Dest = addr
cells, _ := boc.DeserializeBocHex("b5ee9c7201010101000b00001100000000c4d8c2e6e9")
b.Payload[0].Message.MessageExtOut.Body = tlb.EitherRef[ExtOutMsgBody]{
IsRight: false,
Value: ExtOutMsgBody{
SumType: UnknownMsgOp,
OpCode: pointer[uint32](0),
Value: cells[0].CopyRemaining(),
},
}
return b
},
},
}

for _, tt := range tests {
Expand Down Expand Up @@ -1104,15 +1143,20 @@ func TestDecodeExternalIn(t *testing.T) {
if !reflect.DeepEqual(wantValue, value) {
t.Fatalf("want value: \n%v\n, got: \n%v", wantValue, value)
}

var unnmarshaledValue WalletSignedV4ExtInMsgBody
err = json.Unmarshal(b, &unnmarshaledValue)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(unnmarshaledValue, value) {
t.Fatalf("got different result")
switch value.(type) {
case WalletSignedV4ExtInMsgBody:
var unnmarshaledValue WalletSignedV4ExtInMsgBody
err = json.Unmarshal(b, &unnmarshaledValue)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(unnmarshaledValue, value) {
t.Fatalf("got different result")
}
case WalletSignedV3ExtInMsgBody:
// TBD
}

})
}
}
8 changes: 8 additions & 0 deletions abi/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ func (body *InMsgBody) UnmarshalTLB(cell *boc.Cell, decoder *tlb.Decoder) error
body.SumType = *name
body.Value = value
} else {
if cell.BitsAvailableForRead() != cell.BitSize() {
cell = cell.CopyRemaining() //because body can be part of the message cell
}
body.Value = cell
}
return nil
Expand Down Expand Up @@ -166,6 +169,11 @@ func (b *ExtOutMsgBody) UnmarshalTLB(cell *boc.Cell, decoder *tlb.Decoder) error
if name != nil {
b.SumType = *name
b.Value = value
} else {
if cell.BitsAvailableForRead() != cell.BitSize() {
cell = cell.CopyRemaining() //because body can be part of the message cell
}
b.Value = cell
}
return nil
}
Expand Down

0 comments on commit d0953a7

Please sign in to comment.