Skip to content

Commit

Permalink
Create a test for the PrecomputeAddress function
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagodeev committed Jun 12, 2024
1 parent a295a02 commit 2adf264
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions contracts/contracts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (
"os"
"testing"

"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/starknet.go/contracts"
"github.com/NethermindEth/starknet.go/rpc"
"github.com/NethermindEth/starknet.go/utils"
"github.com/test-go/testify/assert"
"github.com/test-go/testify/require"
)
Expand All @@ -19,7 +21,8 @@ import (
// Parameters:
// - t: The testing.T instance for running the test
// Returns:
// none
//
// none
func TestUnmarshalContractClass(t *testing.T) {
content, err := os.ReadFile("./tests/hello_starknet_compiled.sierra.json")
require.NoError(t, err)
Expand All @@ -40,7 +43,8 @@ func TestUnmarshalContractClass(t *testing.T) {
// Parameters:
// - t: The testing.T instance for running the test
// Returns:
// none
//
// none
func TestUnmarshalCasmClass(t *testing.T) {
casmClass, err := contracts.UnmarshalCasmClass("./tests/hello_starknet_compiled.casm.json")
require.NoError(t, err)
Expand All @@ -50,3 +54,30 @@ func TestUnmarshalCasmClass(t *testing.T) {
assert.Equal(t, casmClass.EntryPointByType.External[1].Offset, 130)
assert.Equal(t, casmClass.EntryPointByType.External[1].Builtins[0], "range_check")
}

func TestPrecomputeAddress(t *testing.T) {

deployerAddress := utils.TestHexToFelt(t, "0xdeadbeef")
salts := []*felt.Felt{
utils.TestHexToFelt(t, "0xaaaaaaaa"),
utils.TestHexToFelt(t, "0xbbbbbbbb"),
utils.TestHexToFelt(t, "0xcccccccc"),
}
classHash := utils.TestHexToFelt(t, "0xdeadbeef")
constructorCalldata := []*felt.Felt{
deployerAddress,
}

expectedPrecomputedAddress := []*felt.Felt{
utils.TestHexToFelt(t, "0x3791840c6746577f27f4a5766a6862b7486f0a254d34e0d2f0a5d238160cf10"),
utils.TestHexToFelt(t, "0x479b5192d4af71279a92eddb09e4dcfdc00751ccb27da0e9c4f9b2312318242"),
utils.TestHexToFelt(t, "0x7a824044120ac54527d701e18b2eea6e11fb0a8f070a21acd13a7a4062065b4"),
}

for index := 0; index < 3; index++ {
precomputedAddress, err := contracts.PrecomputeAddress(deployerAddress, salts[index], classHash, constructorCalldata)
require.NoError(t, err)
require.Equal(t, expectedPrecomputedAddress[index], precomputedAddress)
t.Log(precomputedAddress)
}
}

0 comments on commit 2adf264

Please sign in to comment.