Skip to content

Commit

Permalink
use mocks to test TxHash instead of requiring integration endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
rianhughes committed Nov 23, 2023
1 parent a71523f commit ee2ffb2
Showing 1 changed file with 13 additions and 45 deletions.
58 changes: 13 additions & 45 deletions account/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -737,14 +737,12 @@ func TestTransactionHashDeployAccountTestnet(t *testing.T) {
//
// none
func TestTransactionHashDeclare(t *testing.T) {
if testEnv != "testnet" {
t.Skip("Skipping test as it requires a integration environment")
}
client, err := rpc.NewClient(base)
require.NoError(t, err, "Error in rpc.NewClient")
provider := rpc.NewProvider(client)
mockCtrl := gomock.NewController(t)
t.Cleanup(mockCtrl.Finish)
mockRpcProvider := mocks.NewMockRpcProvider(mockCtrl)
mockRpcProvider.EXPECT().ChainID(context.Background()).Return("SN_GOERLI", nil)

acnt, err := account.NewAccount(provider, &felt.Zero, "", account.NewMemKeystore())
acnt, err := account.NewAccount(mockRpcProvider, &felt.Zero, "", account.NewMemKeystore())
require.NoError(t, err)

type testSetType struct {
Expand All @@ -753,7 +751,8 @@ func TestTransactionHashDeclare(t *testing.T) {
ExpectedErr error
}
testSet := map[string][]testSetType{
"testnet": {{
"mock": {{
// Note this is a testnet / goerli transaction
Txn: rpc.DeclareTxnV2{
Nonce: utils.TestHexToFelt(t, "0xb"),
MaxFee: utils.TestHexToFelt(t, "0x50c8f3053db"),
Expand All @@ -767,33 +766,6 @@ func TestTransactionHashDeclare(t *testing.T) {
ExpectedHash: utils.TestHexToFelt(t, "0x4e0519272438a3ae0d0fca776136e2bb6fcd5d3b2af47e53575c5874ccfce92"),
ExpectedErr: nil,
},
}}[testEnv]
for _, test := range testSet {
hash, err := acnt.TransactionHashDeclare(test.Txn)
require.Equal(t, test.ExpectedErr, err)
require.Equal(t, test.ExpectedHash.String(), hash.String(), "TransactionHashDeclare not what expected")
}
}

func TestTransactionHashDeclareINTEGRATION(t *testing.T) {
if testEnv != "integration" {
t.Skip("Skipping test as it requires a integration environment")
}
mockCtrl := gomock.NewController(t)
t.Cleanup(mockCtrl.Finish)
mockRpcProvider := mocks.NewMockRpcProvider(mockCtrl)
mockRpcProvider.EXPECT().ChainID(context.Background()).Return("SN_GOERLI", nil)

acnt, err := account.NewAccount(mockRpcProvider, &felt.Zero, "", account.NewMemKeystore())
require.NoError(t, err)

type testSetType struct {
Txn rpc.DeclareTxnType
ExpectedHash *felt.Felt
ExpectedErr error
}
testSet := map[string][]testSetType{
"integration": {
{
// https://external.integration.starknet.io/feeder_gateway/get_transaction?transactionHash=0x41d1f5206ef58a443e7d3d1ca073171ec25fa75313394318fc83a074a6631c3
Txn: rpc.DeclareTxnV3{
Expand Down Expand Up @@ -833,10 +805,8 @@ func TestTransactionHashDeclareINTEGRATION(t *testing.T) {
}
}

func TestTransactionHashInvokeINTEGRATION(t *testing.T) {
if testEnv != "integration" {
t.Skip("Skipping test as it requires a integration environment")
}
func TestTransactionHashInvokeV3(t *testing.T) {

mockCtrl := gomock.NewController(t)
t.Cleanup(mockCtrl.Finish)
mockRpcProvider := mocks.NewMockRpcProvider(mockCtrl)
Expand All @@ -851,7 +821,7 @@ func TestTransactionHashInvokeINTEGRATION(t *testing.T) {
ExpectedErr error
}
testSet := map[string][]testSetType{
"integration": {
"mock": {
{
// https://external.integration.starknet.io/feeder_gateway/get_transaction?transactionHash=0x49728601e0bb2f48ce506b0cbd9c0e2a9e50d95858aa41463f46386dca489fd
Txn: rpc.InvokeTxnV3{
Expand Down Expand Up @@ -906,10 +876,8 @@ func TestTransactionHashInvokeINTEGRATION(t *testing.T) {
}
}

func TestTransactionHashdeployAccountINTEGRATION(t *testing.T) {
if testEnv != "integration" {
t.Skip("Skipping test as it requires a integration environment")
}
func TestTransactionHashdeployAccount(t *testing.T) {

mockCtrl := gomock.NewController(t)
t.Cleanup(mockCtrl.Finish)
mockRpcProvider := mocks.NewMockRpcProvider(mockCtrl)
Expand All @@ -925,7 +893,7 @@ func TestTransactionHashdeployAccountINTEGRATION(t *testing.T) {
ExpectedErr error
}
testSet := map[string][]testSetType{
"integration": {
"mock": {
{
// https://external.integration.starknet.io/feeder_gateway/get_transaction?transactionHash=0x29fd7881f14380842414cdfdd8d6c0b1f2174f8916edcfeb1ede1eb26ac3ef0
Txn: rpc.DeployAccountTxnV3{
Expand Down

0 comments on commit ee2ffb2

Please sign in to comment.