-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a7b8b8b
commit 7332617
Showing
2 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
package chainwriter_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/gagliardetto/solana-go" | ||
"github.com/smartcontractkit/chainlink-solana/pkg/solana/chainwriter" | ||
"github.com/test-go/testify/require" | ||
) | ||
|
||
type TestArgs struct { | ||
Inner []InnerArgs | ||
} | ||
|
||
type InnerArgs struct { | ||
Address []byte | ||
} | ||
|
||
func TestAccountContant(t *testing.T) { | ||
|
||
t.Run("AccountConstant resolves valid address", func(t *testing.T) { | ||
expectedAddr := "4Nn9dsYBcSTzRbK9hg9kzCUdrCSkMZq1UR6Vw1Tkaf6M" | ||
expectedMeta := []*solana.AccountMeta{ | ||
{ | ||
PublicKey: solana.MustPublicKeyFromBase58(expectedAddr), | ||
IsSigner: true, | ||
IsWritable: true, | ||
}, | ||
} | ||
constantConfig := chainwriter.AccountConstant{ | ||
Name: "TestAccount", | ||
Address: expectedAddr, | ||
IsSigner: true, | ||
IsWritable: true, | ||
} | ||
result, err := constantConfig.Resolve(nil, nil, nil, "") | ||
require.NoError(t, err) | ||
require.Equal(t, expectedMeta, result) | ||
}) | ||
} | ||
func TestAccountLookups(t *testing.T) { | ||
t.Run("AccountLookup resolves valid address with just one address", func(t *testing.T) { | ||
expectedAddr := "4Nn9dsYBcSTzRbK9hg9kzCUdrCSkMZq1UR6Vw1Tkaf6M" | ||
testArgs := TestArgs{ | ||
Inner: []InnerArgs{ | ||
{Address: solana.MustPublicKeyFromBase58(expectedAddr).Bytes()}, | ||
}, | ||
} | ||
expectedMeta := []*solana.AccountMeta{ | ||
{ | ||
PublicKey: solana.MustPublicKeyFromBase58(expectedAddr), | ||
IsSigner: true, | ||
IsWritable: true, | ||
}, | ||
} | ||
|
||
lookupConfig := chainwriter.AccountLookup{ | ||
Name: "TestAccount", | ||
Location: "Inner.Address", | ||
IsSigner: true, | ||
IsWritable: true, | ||
} | ||
result, err := lookupConfig.Resolve(nil, testArgs, nil, "") | ||
require.NoError(t, err) | ||
require.Equal(t, expectedMeta, result) | ||
}) | ||
|
||
t.Run("AccountLookup resolves valid address with just multiple addresses", func(t *testing.T) { | ||
expectedAddr1 := "4Nn9dsYBcSTzRbK9hg9kzCUdrCSkMZq1UR6Vw1Tkaf6M" | ||
expectedAddr2 := "4Nn9dsYBcSTzRbK9hg9kzCUdrCSkMZq1UR6Vw1Tkaf6N" | ||
testArgs := TestArgs{ | ||
Inner: []InnerArgs{ | ||
{Address: solana.MustPublicKeyFromBase58(expectedAddr1).Bytes()}, | ||
{Address: solana.MustPublicKeyFromBase58(expectedAddr2).Bytes()}, | ||
}, | ||
} | ||
expectedMeta := []*solana.AccountMeta{ | ||
{ | ||
PublicKey: solana.MustPublicKeyFromBase58(expectedAddr1), | ||
IsSigner: true, | ||
IsWritable: true, | ||
}, | ||
{ | ||
PublicKey: solana.MustPublicKeyFromBase58(expectedAddr2), | ||
IsSigner: true, | ||
IsWritable: true, | ||
}, | ||
} | ||
|
||
lookupConfig := chainwriter.AccountLookup{ | ||
Name: "TestAccount", | ||
Location: "Inner.Address", | ||
IsSigner: true, | ||
IsWritable: true, | ||
} | ||
result, err := lookupConfig.Resolve(nil, testArgs, nil, "") | ||
require.NoError(t, err) | ||
for i, meta := range result { | ||
require.Equal(t, expectedMeta[i], meta) | ||
} | ||
}) | ||
|
||
t.Run("AccountLookup fails when address isn't in args", func(t *testing.T) { | ||
expectedAddr := "4Nn9dsYBcSTzRbK9hg9kzCUdrCSkMZq1UR6Vw1Tkaf6M" | ||
testArgs := TestArgs{ | ||
Inner: []InnerArgs{ | ||
{Address: solana.MustPublicKeyFromBase58(expectedAddr).Bytes()}, | ||
}, | ||
} | ||
lookupConfig := chainwriter.AccountLookup{ | ||
Name: "InvalidAccount", | ||
Location: "Invalid.Directory", | ||
IsSigner: true, | ||
IsWritable: true, | ||
} | ||
_, err := lookupConfig.Resolve(nil, testArgs, nil, "") | ||
require.Error(t, err) | ||
}) | ||
} | ||
|
||
func TestPDALookups(t *testing.T) { | ||
t.Run("PDALookup resolves valid address", func(t *testing.T) { | ||
expectedAddr := "4Nn9dsYBcSTzRbK9hg9kzCUdrCSkMZq1UR6Vw1Tkaf6M" | ||
expectedMeta := []*solana.AccountMeta{ | ||
{ | ||
PublicKey: solana.MustPublicKeyFromBase58(expectedAddr), | ||
IsSigner: true, | ||
IsWritable: true, | ||
}, | ||
} | ||
lookupConfig := chainwriter.PDALookups{ | ||
Name: "TestAccount", | ||
PublicKey: | ||
} | ||
|
||
}) | ||
} |