Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rianhughes committed Sep 28, 2023
1 parent 81d488e commit 4389343
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 23 deletions.
37 changes: 26 additions & 11 deletions account/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/NethermindEth/starknet.go/artifacts"
hash "github.com/NethermindEth/starknet.go/hash"
"github.com/NethermindEth/starknet.go/mocks"
newcontract "github.com/NethermindEth/starknet.go/newcontracts"
"github.com/NethermindEth/starknet.go/rpc"
"github.com/NethermindEth/starknet.go/test"
"github.com/NethermindEth/starknet.go/types"
Expand Down Expand Up @@ -544,38 +545,52 @@ func TestAddDeclare(t *testing.T) {
require.NoError(t, err, "Error in rpc.NewClient")
provider := rpc.NewProvider(client)

acnt, err := account.NewAccount(provider, &felt.Zero, "", starknetgo.NewMemKeystore())
AccountAddress := utils.TestHexToFelt(t, "0x0088d0038623a89bf853c70ea68b1062ccf32b094d1d7e5f924cda8404dc73e1")
PubKey := utils.TestHexToFelt(t, "0x7ed3c6482e12c3ef7351214d1195ee7406d814af04a305617599ff27be43883")
PrivKey := utils.TestHexToFelt(t, "0x07514c4f0de1f800b0b0c7377ef39294ce218a7abd9a1c9b6aa574779f7cdc6a")

ks := starknetgo.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)

compiledClass := artifacts.HelloWorldSierra

casmClass, err := newcontract.UnmarshalCasmClass("../artifacts/starknet_hello_world_Balance.casm.json")
require.NoError(t, err)
compiledClassHash, err := hash.CompiledClassHash(*casmClass) // Todo pass tests on this first.
require.NoError(t, err)

qweqwe, _ := json.MarshalIndent(casmClass, "", "")
fmt.Println(string(qweqwe))

var class rpc.ContractClass
err = json.Unmarshal(compiledClass, &class)
require.NoError(t, err, "Error in json.Unmarshal(compiledClass, &class)")
classHash, err := hash.ClassHash(class)
require.NoError(t, err, "Error in newcontract.ClassHash(class)")
// classHash, err := hash.ClassHash(class)
// require.NoError(t, err, "Error in newcontract.ClassHash(class)")

tx := rpc.DeclareTxnV2{
Nonce: utils.TestHexToFelt(t, "0xb"),
MaxFee: utils.TestHexToFelt(t, "0x50c8f3053db"),
Type: rpc.TransactionType_Declare,
Version: rpc.TransactionV2,
Signature: []*felt.Felt{},
SenderAddress: utils.TestHexToFelt(t, "0x36437dffa1b0bf630f04690a3b302adbabb942deb488ea430660c895ff25acf"),
ClassHash: classHash,
ContractClass: class,
SenderAddress: utils.TestHexToFelt(t, "0x0088d0038623a89bf853c70ea68b1062ccf32b094d1d7e5f924cda8404dc73e1"),
// ClassHash: classHash, // This field isn't accepted by the sequencer..
ContractClass: class,
CompiledClassHash: compiledClassHash,
}

err = acnt.SignDeclareTransaction(context.Background(), &tx)
require.NoError(t, err, "Error in SignDeclareTransaction")

qwe, _ := json.MarshalIndent(tx, "", "")
fmt.Println(string(qwe))

hash, err := acnt.TransactionHashDeclare(tx)
hash, err := acnt.AddDeclareTransaction(context.Background(), tx)
require.NoError(t, err)
fmt.Println("HASH", hash)

}

func newDevnet(t *testing.T, url string) ([]test.TestAccount, error) {
Expand Down
11 changes: 11 additions & 0 deletions hash/hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,14 @@ func TestUnmarshalCasmClassHash(t *testing.T) {
err := json.Unmarshal(compiledClass, &class)
require.NoError(t, err)
}

func TestCompiledClassHash(t *testing.T) {
expectedHash := "0x_todo_"

casmClass, err := newcontract.UnmarshalCasmClass("../artifacts/starknet_hello_world_Balance.casm.json")
require.NoError(t, err)

hash, err := hash.CompiledClassHash(*casmClass)
require.NoError(t, err)
require.Equal(t, expectedHash, hash.String())
}
12 changes: 0 additions & 12 deletions newcontracts/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"testing"

"github.com/NethermindEth/starknet.go/artifacts"
"github.com/NethermindEth/starknet.go/hash"
newcontract "github.com/NethermindEth/starknet.go/newcontracts"
"github.com/NethermindEth/starknet.go/rpc"
"github.com/test-go/testify/require"
Expand All @@ -30,14 +29,3 @@ func TestUnmarshalCasmClass(t *testing.T) {
require.Equal(t, casmClass.EntryPointByType.External[1].Offset, 111)
require.Equal(t, casmClass.EntryPointByType.External[1].Builtins[0], "range_check")
}

func TestCompiledClassHash(t *testing.T) {
expectedHash := "0x_todo_"

casmClass, err := newcontract.UnmarshalCasmClass("../artifacts/starknet_hello_world_Balance.casm.json")
require.NoError(t, err)

hash, err := hash.CompiledClassHash(*casmClass)
require.NoError(t, err)
require.Equal(t, expectedHash, hash.String())
}

0 comments on commit 4389343

Please sign in to comment.