Skip to content

Commit f00972e

Browse files
authored
fix: retain data on CBOR unmarshal of native script (#1140)
This also adds a test for generating the native script hash Fixes #1139 Signed-off-by: Aurora Gaffney <[email protected]>
1 parent d7d6eff commit f00972e

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

ledger/common/script.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ func (n *NativeScript) UnmarshalCBOR(data []byte) error {
158158
if _, err := cbor.Decode(data, tmpData); err != nil {
159159
return err
160160
}
161+
n.item = tmpData
161162
return nil
162163
}
163164

ledger/common/script_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ func TestScriptRefDecode(t *testing.T) {
4141
}
4242
}
4343

44+
func TestNativeScriptHash(t *testing.T) {
45+
testScriptBytes, _ := hex.DecodeString("820181830301838200581c058a5ab0c66647dcce82d7244f80bfea41ba76c7c9ccaf86a41b00fe8200581c45cbc234959cb619ef54e36c16e7719318592e627cdf1a39bd3d64398200581c85fd53e110449649b709ef0fa93e86d99535bdce5db306ce0e7418fc")
46+
expectedScriptHash := "1c0053ec18e2c0f7bd4d007fe14243ca220563f9c124381f75c43704"
47+
var testScript common.NativeScript
48+
if err := testScript.UnmarshalCBOR(testScriptBytes); err != nil {
49+
t.Fatalf("unexpected error decoding native script: %s", err)
50+
}
51+
tmpHash := testScript.Hash()
52+
if tmpHash.String() != expectedScriptHash {
53+
t.Errorf("did not get expected script hash, got %s, wanted %s", tmpHash.String(), expectedScriptHash)
54+
}
55+
}
56+
4457
func TestPlutusV3ScriptHash(t *testing.T) {
4558
testScriptBytes, _ := hex.DecodeString("587f01010032323232323225333002323232323253330073370e900118041baa0011323232533300a3370e900018059baa00513232533300f301100214a22c6eb8c03c004c030dd50028b18069807001180600098049baa00116300a300b0023009001300900230070013004375400229309b2b2b9a5573aaae7955cfaba157441")
4659
testScript := common.PlutusV3Script(testScriptBytes)

0 commit comments

Comments
 (0)