-
Notifications
You must be signed in to change notification settings - Fork 20
feat(ledger): Add friendly string representation of TX outputs #1174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
33aed59
be52da6
33ee0d8
57ff156
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -277,3 +277,23 @@ func TestAlonzoRedeemersIter(t *testing.T) { | |
iterIdx++ | ||
} | ||
} | ||
|
||
func TestAlonzoTransactionOutputString(t *testing.T) { | ||
addr, _ := common.NewAddress( | ||
"addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd", | ||
) | ||
ma := common.NewMultiAsset[common.MultiAssetTypeOutput]( | ||
map[common.Blake2b224]map[cbor.ByteString]uint64{ | ||
common.NewBlake2b224(make([]byte, 28)): {cbor.NewByteString([]byte("t")): 2}, | ||
}, | ||
) | ||
out := AlonzoTransactionOutput{ | ||
OutputAddress: addr, | ||
OutputAmount: mary.MaryTransactionOutputValue{Amount: 456, Assets: &ma}, | ||
} | ||
s := out.String() | ||
expected := "(AlonzoTransactionOutput address=" + addr.String() + " amount=456 assets=...)" | ||
|
||
if s != expected { | ||
t.Fatalf("unexpected string: %s", s) | ||
} | ||
agaffney marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -649,6 +649,19 @@ func (o BabbageTransactionOutput) Utxorpc() (*utxorpc.TxOutput, error) { | |
nil | ||
} | ||
|
||
func (o BabbageTransactionOutput) String() string { | ||
assets := "" | ||
if o.OutputAmount.Assets != nil && len(o.OutputAmount.Assets.Policies()) > 0 { | ||
assets = " assets=..." | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should build out a list of the assets for the string output |
||
return fmt.Sprintf( | ||
"(BabbageTransactionOutput address=%s amount=%d%s)", | ||
o.OutputAddress.String(), | ||
o.OutputAmount.Amount, | ||
assets, | ||
) | ||
} | ||
|
||
type BabbageTransactionWitnessSet struct { | ||
cbor.DecodeStoreCbor | ||
VkeyWitnesses []common.VkeyWitness `cbor:"0,keyasint,omitempty"` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2970,3 +2970,23 @@ func TestBabbageTransactionOutputToPlutusDataCoinAssets(t *testing.T) { | |
) | ||
} | ||
} | ||
|
||
func TestBabbageTransactionOutputString(t *testing.T) { | ||
addr, _ := common.NewAddress( | ||
"addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd", | ||
) | ||
ma := common.NewMultiAsset[common.MultiAssetTypeOutput]( | ||
map[common.Blake2b224]map[cbor.ByteString]uint64{ | ||
common.NewBlake2b224(make([]byte, 28)): {cbor.NewByteString([]byte("x")): 2}, | ||
}, | ||
) | ||
out := BabbageTransactionOutput{ | ||
OutputAddress: addr, | ||
OutputAmount: mary.MaryTransactionOutputValue{Amount: 456, Assets: &ma}, | ||
} | ||
s := out.String() | ||
expected := "(BabbageTransactionOutput address=" + addr.String() + " amount=456 assets=...)" | ||
|
||
if s != expected { | ||
t.Fatalf("unexpected string: %s", s) | ||
} | ||
agaffney marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,3 +104,23 @@ func TestByronTransaction_Utxorpc_Empty(t *testing.T) { | |
t.Errorf("Expected fee = 0, got %d", result.Fee) | ||
} | ||
} | ||
|
||
func TestByronTransactionOutputString(t *testing.T) { | ||
addr, err := common.NewByronAddressFromParts( | ||
0, | ||
make([]byte, common.AddressHashSize), | ||
common.ByronAddressAttributes{}, | ||
) | ||
if err != nil { | ||
t.Fatalf("address: %v", err) | ||
} | ||
out := byron.ByronTransactionOutput{ | ||
OutputAddress: addr, | ||
OutputAmount: 456, | ||
} | ||
s := out.String() | ||
expected := "(ByronTransactionOutput address=" + addr.String() + " amount=456)" | ||
|
||
if s != expected { | ||
t.Fatalf("unexpected string: %s", s) | ||
} | ||
agaffney marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ package mary | |
|
||
import ( | ||
"encoding/hex" | ||
"fmt" | ||
"reflect" | ||
"testing" | ||
|
||
|
@@ -115,3 +116,34 @@ func TestMaryTransactionOutputValueEncodeDecode(t *testing.T) { | |
} | ||
} | ||
} | ||
|
||
func TestMaryTransactionOutputString(t *testing.T) { | ||
addr, _ := common.NewAddress("addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd") | ||
ma := common.NewMultiAsset[common.MultiAssetTypeOutput]( | ||
map[common.Blake2b224]map[cbor.ByteString]uint64{ | ||
common.NewBlake2b224(make([]byte, 28)): {cbor.NewByteString([]byte("token")): 2}, | ||
}, | ||
) | ||
out := MaryTransactionOutput{ | ||
OutputAddress: addr, | ||
OutputAmount: MaryTransactionOutputValue{Amount: 456, Assets: &ma}, | ||
} | ||
s := out.String() | ||
expected := fmt.Sprintf("(MaryTransactionOutput address=%s amount=456 assets=...)", addr.String()) | ||
|
||
if s != expected { | ||
t.Fatalf("unexpected string: %s", s) | ||
} | ||
agaffney marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
func TestMaryOutputTooBigErrorFormatting(t *testing.T) { | ||
addr, _ := common.NewAddress("addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd") | ||
out := &MaryTransactionOutput{ | ||
OutputAddress: addr, | ||
OutputAmount: MaryTransactionOutputValue{Amount: 456}, | ||
} | ||
errStr := OutputTooBigUtxoError{Outputs: []common.TransactionOutput{out}}.Error() | ||
expected := fmt.Sprintf("output value too large: (MaryTransactionOutput address=%s amount=456)", addr.String()) | ||
|
||
if errStr != expected { | ||
t.Fatalf("unexpected error: %s", errStr) | ||
} | ||
agaffney marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package shelley_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/blinklabs-io/gouroboros/ledger/common" | ||
"github.com/blinklabs-io/gouroboros/ledger/shelley" | ||
) | ||
|
||
func TestShelleyTransactionOutputString(t *testing.T) { | ||
addr, _ := common.NewAddress("addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd") | ||
out := shelley.ShelleyTransactionOutput{ | ||
OutputAddress: addr, | ||
OutputAmount: 456, | ||
} | ||
s := out.String() | ||
expected := fmt.Sprintf("(ShelleyTransactionOutput address=%s amount=456)", addr.String()) | ||
|
||
if s != expected { | ||
t.Fatalf("unexpected string: %s", s) | ||
} | ||
agaffney marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
func TestShelleyOutputTooSmallErrorFormatting(t *testing.T) { | ||
addr, _ := common.NewAddress("addr1qytna5k2fq9ler0fuk45j7zfwv7t2zwhp777nvdjqqfr5tz8ztpwnk8zq5ngetcz5k5mckgkajnygtsra9aej2h3ek5seupmvd") | ||
out := &shelley.ShelleyTransactionOutput{ | ||
OutputAddress: addr, | ||
OutputAmount: 456, | ||
} | ||
errStr := shelley.OutputTooSmallUtxoError{Outputs: []common.TransactionOutput{out}}.Error() | ||
expected := fmt.Sprintf("output too small: (ShelleyTransactionOutput address=%s amount=456)", addr.String()) | ||
|
||
if errStr != expected { | ||
t.Fatalf("unexpected error: %s", errStr) | ||
} | ||
agaffney marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
Uh oh!
There was an error while loading. Please reload this page.