github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/chat/wallet/decorate_test.go (about)

     1  package wallet
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/keybase/client/go/protocol/chat1"
     8  	"github.com/keybase/client/go/protocol/stellar1"
     9  	"github.com/stretchr/testify/require"
    10  )
    11  
    12  type decorateTest struct {
    13  	body     string
    14  	payments []chat1.TextPayment
    15  	result   string
    16  }
    17  
    18  func TestStellarDecorate(t *testing.T) {
    19  	cases := []decorateTest{
    20  		{
    21  			body: "+1xlm other test",
    22  			payments: []chat1.TextPayment{
    23  				{
    24  					Username:    "mikem",
    25  					PaymentText: "+1XLM",
    26  					Result:      chat1.NewTextPaymentResultWithSent(stellar1.PaymentID("stellarid")),
    27  				},
    28  			},
    29  			// {"typ":0,"payment":{"username":"mikem","paymentText":"+1XLM","result":{"resultTyp":0,"sent":"stellarid"}}}
    30  			result: "$>kb$eyJ0eXAiOjAsInBheW1lbnQiOnsidXNlcm5hbWUiOiJtaWtlbSIsInBheW1lbnRUZXh0IjoiKzFYTE0iLCJyZXN1bHQiOnsicmVzdWx0VHlwIjowLCJzZW50Ijoic3RlbGxhcmlkIn19fQ==$<kb$ other test",
    31  		},
    32  		{
    33  			body: "`+1xlm` +1xlm other test",
    34  			payments: []chat1.TextPayment{
    35  				{
    36  					Username:    "mikem",
    37  					PaymentText: "+1XLM",
    38  					Result:      chat1.NewTextPaymentResultWithSent(stellar1.PaymentID("stellarid")),
    39  				},
    40  			},
    41  			// {"typ":0,"payment":{"username":"mikem","paymentText":"+1XLM","result":{"resultTyp":0,"sent":"stellarid"}}}
    42  			result: "`+1xlm` $>kb$eyJ0eXAiOjAsInBheW1lbnQiOnsidXNlcm5hbWUiOiJtaWtlbSIsInBheW1lbnRUZXh0IjoiKzFYTE0iLCJyZXN1bHQiOnsicmVzdWx0VHlwIjowLCJzZW50Ijoic3RlbGxhcmlkIn19fQ==$<kb$ other test",
    43  		},
    44  		{
    45  			body: "HIHIH ```+5xlm@patrick``` +5xlm@patrick `+1xlm` +1xlm other test",
    46  			payments: []chat1.TextPayment{
    47  				{
    48  					Username:    "patrick",
    49  					PaymentText: "+5XLM@patrick",
    50  					Result:      chat1.NewTextPaymentResultWithSent(stellar1.PaymentID("stellarid")),
    51  				},
    52  				{
    53  					Username:    "mikem",
    54  					PaymentText: "+1XLM",
    55  					Result:      chat1.NewTextPaymentResultWithSent(stellar1.PaymentID("stellarid")),
    56  				},
    57  			},
    58  			// {"typ":0,"payment":{"username":"patrick","paymentText":"+5XLM@patrick","result":{"resultTyp":0,"sent":"stellarid"}}}
    59  			// {"typ":0,"payment":{"username":"mikem","paymentText":"+1XLM","result":{"resultTyp":0,"sent":"stellarid"}}}
    60  			result: "HIHIH ```+5xlm@patrick``` $>kb$eyJ0eXAiOjAsInBheW1lbnQiOnsidXNlcm5hbWUiOiJwYXRyaWNrIiwicGF5bWVudFRleHQiOiIrNVhMTUBwYXRyaWNrIiwicmVzdWx0Ijp7InJlc3VsdFR5cCI6MCwic2VudCI6InN0ZWxsYXJpZCJ9fX0=$<kb$ `+1xlm` $>kb$eyJ0eXAiOjAsInBheW1lbnQiOnsidXNlcm5hbWUiOiJtaWtlbSIsInBheW1lbnRUZXh0IjoiKzFYTE0iLCJyZXN1bHQiOnsicmVzdWx0VHlwIjowLCJzZW50Ijoic3RlbGxhcmlkIn19fQ==$<kb$ other test",
    61  		},
    62  		{
    63  			body: "   ```   `+124.004XLM@max```  my life to yours, my breath become yours  ```   ` +124.005XLM@mikem ``    ",
    64  			payments: []chat1.TextPayment{
    65  				{
    66  					Username:    "mikem",
    67  					PaymentText: "+124.005XLM@mikem",
    68  					Result:      chat1.NewTextPaymentResultWithSent(stellar1.PaymentID("stellarid")),
    69  				},
    70  			},
    71  			// {"typ":0,"payment":{"username":"mikem","paymentText":"+124.005XLM@mikem","result":{"resultTyp":0,"sent":"stellarid"}}}
    72  			result: "   ```   `+124.004XLM@max```  my life to yours, my breath become yours  ```   ` $>kb$eyJ0eXAiOjAsInBheW1lbnQiOnsidXNlcm5hbWUiOiJtaWtlbSIsInBheW1lbnRUZXh0IjoiKzEyNC4wMDVYTE1AbWlrZW0iLCJyZXN1bHQiOnsicmVzdWx0VHlwIjowLCJzZW50Ijoic3RlbGxhcmlkIn19fQ==$<kb$ ``    ",
    73  		},
    74  	}
    75  	for i, c := range cases {
    76  		res := DecorateWithPayments(context.TODO(), c.body, c.payments)
    77  		require.Equal(t, c.result, res, "unit %v", i)
    78  	}
    79  }