|
| 1 | +// Copyright 2025 Blink Labs Software |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package shelley_test |
| 16 | + |
| 17 | +import ( |
| 18 | + "encoding/hex" |
| 19 | + "math/big" |
| 20 | + "reflect" |
| 21 | + "testing" |
| 22 | + |
| 23 | + "github.com/blinklabs-io/gouroboros/ledger/shelley" |
| 24 | + "github.com/blinklabs-io/plutigo/pkg/data" |
| 25 | +) |
| 26 | + |
| 27 | +func TestShelleyTransactionInputToPlutusData(t *testing.T) { |
| 28 | + testTxIdHex := "1639f61ed08f5e489dd64db20f86451a0db06e83d21ea39c73ea0a93b478a370" |
| 29 | + testTxOutputIdx := 2 |
| 30 | + testInput := shelley.NewShelleyTransactionInput( |
| 31 | + testTxIdHex, |
| 32 | + testTxOutputIdx, |
| 33 | + ) |
| 34 | + testTxId, err := hex.DecodeString(testTxIdHex) |
| 35 | + if err != nil { |
| 36 | + t.Fatalf("unexpected error: %s", err) |
| 37 | + } |
| 38 | + expectedData := data.NewConstr( |
| 39 | + 0, |
| 40 | + []data.PlutusData{ |
| 41 | + data.NewByteString(testTxId), |
| 42 | + data.NewInteger(big.NewInt(int64(testTxOutputIdx))), |
| 43 | + }, |
| 44 | + ) |
| 45 | + tmpData := testInput.ToPlutusData() |
| 46 | + if !reflect.DeepEqual(tmpData, expectedData) { |
| 47 | + t.Fatalf("did not get expected PlutusData\n got: %#v\n wanted: %#v", tmpData, expectedData) |
| 48 | + } |
| 49 | +} |
0 commit comments