Skip to content

Commit

Permalink
fix TestGenesisStateDiff - wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rian committed May 2, 2024
1 parent bf83e71 commit 5fe15df
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
25 changes: 15 additions & 10 deletions genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ func Read(path string) (*GenesisConfig, error) {
}

type GenesisContractData struct {
ClassHash felt.Felt `json:"class_hash"`
ConstructorArgs []felt.Felt `json:"constructor_args"`
ClassHash felt.Felt `json:"class_hash"`
ConstructorArgs []felt.Felt `json:"constructor_args"`
ConstructorSelector felt.Felt `json:"constructor_entry_point_selector"`
}

type FunctionCall struct {
Expand Down Expand Up @@ -78,11 +79,6 @@ func GenesisStateDiff(
}
}

constructorSelector, err := new(felt.Felt).SetString("0x28ffe4ff0f226a9107253e17a904099aa4f63a02a5621de0576e5aa71bc5194")
if err != nil {
return nil, nil, fmt.Errorf("convert string to felt: %v", err)
}

for addressFelt, contractData := range config.Contracts {
classHash := contractData.ClassHash
if err = genesisState.SetClassHash(&addressFelt, &classHash); err != nil {
Expand All @@ -91,13 +87,18 @@ func GenesisStateDiff(

if contractData.ConstructorArgs != nil {
// Call the constructors
blockInfo := vm.BlockInfo{} // Todo
blockInfo := vm.BlockInfo{
Header: &core.Header{
Number: 0,
},
}
calInfo := vm.CallInfo{
ContractAddress: &addressFelt,
ClassHash: &classHash,
Selector: constructorSelector,
Selector: &contractData.ConstructorSelector,

Check failure on line 98 in genesis/genesis.go

View workflow job for this annotation

GitHub Actions / lint

G601: Implicit memory aliasing in for loop. (gosec)
Calldata: contractData.ConstructorArgs,
}
fmt.Println("classHash", classHash.String(), contractData.ConstructorSelector.String()) // Todo: contractData.ConstructorSelector is being overwritten

Check failure on line 101 in genesis/genesis.go

View workflow job for this annotation

GitHub Actions / lint

line is 153 characters (lll)
maxSteps := uint64(1000000000)

Check failure on line 102 in genesis/genesis.go

View workflow job for this annotation

GitHub Actions / lint

mnd: Magic number: 1000000000, in <argument> detected (gomnd)
if _, err = v.Call(&calInfo, &blockInfo, genesisState, network, maxSteps, false); err != nil {
return nil, nil, fmt.Errorf("execute function call: %v", err)
Expand All @@ -112,7 +113,11 @@ func GenesisStateDiff(
if err != nil {
return nil, nil, fmt.Errorf("get contract class hash: %v", err)
}
blockInfo := vm.BlockInfo{} // Todo
blockInfo := vm.BlockInfo{
Header: &core.Header{
Number: 0,
},
} // Todo
calInfo := vm.CallInfo{
ContractAddress: &contractAddress,
ClassHash: classHash,
Expand Down
13 changes: 10 additions & 3 deletions genesis/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ func TestGenesisStateDiff(t *testing.T) {
udcAddress, err := new(felt.Felt).SetString("0xdeadbeef222")
require.NoError(t, err)

defaultConstructorSelector, err := new(felt.Felt).SetString("0x28ffe4ff0f226a9107253e17a904099aa4f63a02a5621de0576e5aa71bc5194")
require.NoError(t, err)
udcConstructorSelector, err := new(felt.Felt).SetString("0x1987cbd17808b9a23693d4de7e246a443cfe37e6e7fbaeabd7d7e6532b07c3d")
require.NoError(t, err)

genesisConfig := genesis.GenesisConfig{
Classes: []string{
"./testdata/simpleStore.json",
Expand All @@ -66,11 +71,13 @@ func TestGenesisStateDiff(t *testing.T) {
},
Contracts: map[felt.Felt]genesis.GenesisContractData{
*simpleStoreAddress: {
ClassHash: *simpleStoreClassHash,
ConstructorArgs: []felt.Felt{*new(felt.Felt).SetUint64(1)},
ClassHash: *simpleStoreClassHash,
ConstructorArgs: []felt.Felt{*new(felt.Felt).SetUint64(1)},
ConstructorSelector: *defaultConstructorSelector,
},
*udcAddress: {
ClassHash: *udcClassHash,
ClassHash: *udcClassHash,
ConstructorSelector: *udcConstructorSelector,
},
},
FunctionCalls: []genesis.FunctionCall{
Expand Down

0 comments on commit 5fe15df

Please sign in to comment.