From 1bc8c1ab865ad299dc616cabf1732a16038d711e Mon Sep 17 00:00:00 2001 From: Marcin Gorzynski Date: Wed, 14 Feb 2024 09:37:03 +0100 Subject: [PATCH] intents: add comment & IntentTyped.AsIntent to IntentTyped.ToIntent --- intents/intent.ridl | 2 +- intents/intent_typed.go | 2 +- intents/intent_typed_test.go | 16 ++++++++-------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/intents/intent.ridl b/intents/intent.ridl index ae1a2cc..8c77961 100644 --- a/intents/intent.ridl +++ b/intents/intent.ridl @@ -70,7 +70,7 @@ struct IntentDataSignMessage struct IntentDataSendTransaction - network: string - wallet: string - - identifier: string + - identifier: string # is used to generate nonce space - transactions: []any + go.field.type = []json.RawMessage diff --git a/intents/intent_typed.go b/intents/intent_typed.go index e9a520e..3a38eae 100644 --- a/intents/intent_typed.go +++ b/intents/intent_typed.go @@ -102,7 +102,7 @@ func (i *IntentTyped[T]) IsValid() error { return nil } -func (i *IntentTyped[T]) AsIntent() *Intent { +func (i *IntentTyped[T]) ToIntent() *Intent { i.Intent.Data = i.Data return &i.Intent } diff --git a/intents/intent_typed_test.go b/intents/intent_typed_test.go index 06c559b..161b275 100644 --- a/intents/intent_typed_test.go +++ b/intents/intent_typed_test.go @@ -93,7 +93,7 @@ func TestIntentIsValid(t *testing.T) { require.NoError(t, err) session := NewSessionP256K1(wallet) - err = session.Sign(intent.AsIntent()) + err = session.Sign(intent.ToIntent()) require.NoError(t, err) assert.NoError(t, intent.IsValid()) @@ -106,7 +106,7 @@ func TestIntentIsValid(t *testing.T) { require.NoError(t, err) session := NewSessionP256K1(wallet) - err = session.Sign(intent.AsIntent()) + err = session.Sign(intent.ToIntent()) require.NoError(t, err) assert.NoError(t, intent.IsValid()) @@ -119,7 +119,7 @@ func TestIntentIsValid(t *testing.T) { require.NoError(t, err) session := NewSessionP256R1(privateKey) - err = session.Sign(intent.AsIntent()) + err = session.Sign(intent.ToIntent()) require.NoError(t, err) assert.NoError(t, intent.IsValid()) @@ -145,7 +145,7 @@ func TestIntentIsValid(t *testing.T) { require.NoError(t, err) session := NewSessionP256K1(wallet) - err = session.Sign(intent.AsIntent()) + err = session.Sign(intent.ToIntent()) require.NoError(t, err) assert.ErrorContains(t, intent.IsValid(), "expired") @@ -159,7 +159,7 @@ func TestIntentIsValid(t *testing.T) { require.NoError(t, err) session := NewSessionP256K1(wallet) - err = session.Sign(intent.AsIntent()) + err = session.Sign(intent.ToIntent()) require.NoError(t, err) assert.ErrorContains(t, intent.IsValid(), "issued in the future") @@ -178,7 +178,7 @@ func TestIntentIsValid(t *testing.T) { require.NoError(t, err) session := NewSessionP256K1(wallet) - err = session.Sign(intent.AsIntent()) + err = session.Sign(intent.ToIntent()) require.NoError(t, err) intent.Signatures[0].Signature = "0x1234" @@ -195,7 +195,7 @@ func TestIntentDataValidator(t *testing.T) { require.NoError(t, err) session := NewSessionP256K1(wallet) - err = session.Sign(intent.AsIntent()) + err = session.Sign(intent.ToIntent()) require.NoError(t, err) assert.NoError(t, intent.IsValid()) @@ -208,7 +208,7 @@ func TestIntentDataValidator(t *testing.T) { require.NoError(t, err) session := NewSessionP256K1(wallet) - err = session.Sign(intent.AsIntent()) + err = session.Sign(intent.ToIntent()) require.NoError(t, err) assert.ErrorContains(t, intent.IsValid(), "invalid intent data")