Skip to content

Commit

Permalink
update transactionHash test to use mocks and not testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
rianhughes committed Nov 23, 2023
1 parent 7b71060 commit 4803431
Showing 1 changed file with 21 additions and 75 deletions.
96 changes: 21 additions & 75 deletions account/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,80 +643,6 @@ func TestAddDeployAccountDevnet(t *testing.T) {
require.NotNil(t, resp, "AddDeployAccountTransaction resp not nil")
}

// TestTransactionHashDeployAccountTestnet tests the TransactionHashDeployAccount function when using the testnet environment.
//
// It creates a client and provider, initializes the required addresses and keys, and sets up the transaction parameters.
// It then precomputes the address and calculates the hash of the transaction.
// Finally, it verifies that the calculated hash matches the expected hash.
//
// Parameters:
// - t: is the testing framework
//
// Returns:
//
// none
func TestTransactionHashDeployAccountTestnet(t *testing.T) {

if testEnv != "testnet" {
t.Skip("Skipping test as it requires a testnet environment")
}

client, err := rpc.NewClient(base)
require.NoError(t, err, "Error in rpc.NewClient")
provider := rpc.NewProvider(client)

AccountAddress := utils.TestHexToFelt(t, "0x0088d0038623a89bf853c70ea68b1062ccf32b094d1d7e5f924cda8404dc73e1")
PubKey := utils.TestHexToFelt(t, "0x7ed3c6482e12c3ef7351214d1195ee7406d814af04a305617599ff27be43883")
PrivKey := utils.TestHexToFelt(t, "0x07514c4f0de1f800b0b0c7377ef39294ce218a7abd9a1c9b6aa574779f7cdc6a")

ks := account.NewMemKeystore()
fakePrivKeyBI, ok := new(big.Int).SetString(PrivKey.String(), 0)
require.True(t, ok)
ks.Put(PubKey.String(), fakePrivKeyBI)

acnt, err := account.NewAccount(provider, AccountAddress, PubKey.String(), ks)
require.NoError(t, err)

classHash := utils.TestHexToFelt(t, "0x3131fa018d520a037686ce3efddeab8f28895662f019ca3ca18a626650f7d1e")

type testSetType struct {
Txn rpc.DeployAccountTxn
ExpectedPrecomputedAddress *felt.Felt
ExpectedHash *felt.Felt
ExpectedErr error
}
testSet := map[string][]testSetType{
"testnet": {{
Txn: rpc.DeployAccountTxn{
Nonce: &felt.Zero,
MaxFee: utils.TestHexToFelt(t, "0x105ef39b2000"),
Type: rpc.TransactionType_DeployAccount,
Version: rpc.TransactionV1,
Signature: []*felt.Felt{},
ClassHash: classHash,
ContractAddressSalt: utils.TestHexToFelt(t, "0x7ed3c6482e12c3ef7351214d1195ee7406d814af04a305617599ff27be43883"),
ConstructorCalldata: []*felt.Felt{
utils.TestHexToFelt(t, "0x5aa23d5bb71ddaa783da7ea79d405315bafa7cf0387a74f4593578c3e9e6570"),
utils.TestHexToFelt(t, "0x2dd76e7ad84dbed81c314ffe5e7a7cacfb8f4836f01af4e913f275f89a3de1a"),
utils.TestHexToFelt(t, "0x1"),
utils.TestHexToFelt(t, "0x7ed3c6482e12c3ef7351214d1195ee7406d814af04a305617599ff27be43883"),
},
},
ExpectedPrecomputedAddress: utils.TestHexToFelt(t, "0x88d0038623a89bf853c70ea68b1062ccf32b094d1d7e5f924cda8404dc73e1"),
ExpectedHash: utils.TestHexToFelt(t, "0x5b6b5927cd70ad7a80efdbe898244525871875c76540b239f6730118598b9cb"),
ExpectedErr: nil,
},
}}[testEnv]
for _, test := range testSet {
precomputedAddress, err := acnt.PrecomputeAddress(&felt.Zero, test.Txn.ContractAddressSalt, classHash, test.Txn.ConstructorCalldata)
require.Equal(t, test.ExpectedPrecomputedAddress.String(), precomputedAddress.String(), "Error with calulcating PrecomputeAddress")

hash, err := acnt.TransactionHashDeployAccount(test.Txn, precomputedAddress)
require.NoError(t, err, "TransactionHashDeployAccount gave an Error")
require.Equal(t, test.ExpectedHash.String(), hash.String(), "Error with calulcating TransactionHashDeployAccount")
}
}

// TestTransactionHashDeclare tests the TransactionHashDeclare function.
//
// This function verifies that the TransactionHashDeclare function returns the
Expand Down Expand Up @@ -887,13 +813,33 @@ func TestTransactionHashdeployAccount(t *testing.T) {
require.NoError(t, err)

type testSetType struct {
Txn rpc.DeployAccountTxnV3
Txn rpc.DeployAccountType
SenderAddress *felt.Felt
ExpectedHash *felt.Felt
ExpectedErr error
}
testSet := map[string][]testSetType{
"mock": {
{
Txn: rpc.DeployAccountTxn{
Nonce: &felt.Zero,
MaxFee: utils.TestHexToFelt(t, "0x105ef39b2000"),
Type: rpc.TransactionType_DeployAccount,
Version: rpc.TransactionV1,
Signature: []*felt.Felt{},
ClassHash: utils.TestHexToFelt(t, "0x3131fa018d520a037686ce3efddeab8f28895662f019ca3ca18a626650f7d1e"),
ContractAddressSalt: utils.TestHexToFelt(t, "0x7ed3c6482e12c3ef7351214d1195ee7406d814af04a305617599ff27be43883"),
ConstructorCalldata: []*felt.Felt{
utils.TestHexToFelt(t, "0x5aa23d5bb71ddaa783da7ea79d405315bafa7cf0387a74f4593578c3e9e6570"),
utils.TestHexToFelt(t, "0x2dd76e7ad84dbed81c314ffe5e7a7cacfb8f4836f01af4e913f275f89a3de1a"),
utils.TestHexToFelt(t, "0x1"),
utils.TestHexToFelt(t, "0x7ed3c6482e12c3ef7351214d1195ee7406d814af04a305617599ff27be43883"),
},
},
SenderAddress: utils.TestHexToFelt(t, "0x88d0038623a89bf853c70ea68b1062ccf32b094d1d7e5f924cda8404dc73e1"),
ExpectedHash: utils.TestHexToFelt(t, "0x5b6b5927cd70ad7a80efdbe898244525871875c76540b239f6730118598b9cb"),
ExpectedErr: nil,
},
{
// https://external.integration.starknet.io/feeder_gateway/get_transaction?transactionHash=0x29fd7881f14380842414cdfdd8d6c0b1f2174f8916edcfeb1ede1eb26ac3ef0
Txn: rpc.DeployAccountTxnV3{
Expand Down

0 comments on commit 4803431

Please sign in to comment.