-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
znn
committed
Jan 22, 2022
1 parent
df3c89d
commit aee7ab6
Showing
49 changed files
with
118,471 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package chain | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/zenon-network/go-zenon/chain/nom" | ||
"github.com/zenon-network/go-zenon/common" | ||
) | ||
|
||
func TestAccountPool_filterBlocksToCommit(t *testing.T) { | ||
ap := accountPool{} | ||
MaxAccountBlocksInMomentum = 2 | ||
common.Expect(t, len(ap.filterBlocksToCommit([]*nom.AccountBlock{ | ||
{Height: 1, BlockType: nom.BlockTypeUserSend}, | ||
{Height: 2, BlockType: nom.BlockTypeUserSend}, | ||
{Height: 3, BlockType: nom.BlockTypeUserSend}, | ||
})), 2) | ||
|
||
common.Expect(t, len(ap.filterBlocksToCommit([]*nom.AccountBlock{ | ||
{Height: 1, BlockType: nom.BlockTypeContractSend}, | ||
{Height: 2, BlockType: nom.BlockTypeContractSend}, | ||
{Height: 3, BlockType: nom.BlockTypeUserReceive}, | ||
})), 0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package genesis | ||
|
||
import ( | ||
"os" | ||
"path" | ||
"testing" | ||
|
||
"github.com/zenon-network/go-zenon/common" | ||
"github.com/zenon-network/go-zenon/common/types" | ||
) | ||
|
||
var ( | ||
emptyGenesisJsonStr = []byte(` | ||
{ | ||
"ChainIdentifier": 100, | ||
"ExtraData": "", | ||
"GenesisTimestampSec": 1000000000, | ||
"SporkAddress": "z1qqv2fnc3avjg39dcste4c5lag7l42xyykjf49w", | ||
"PillarConfig": { | ||
"Pillars": [], | ||
"Delegations": [], | ||
"LegacyEntries": [] | ||
}, | ||
"TokenConfig": { | ||
"Tokens": [] | ||
}, | ||
"PlasmaConfig": { | ||
"Fusions": [] | ||
}, | ||
"SwapConfig": { | ||
"Entries": [] | ||
}, | ||
"SporkConfig": { | ||
"Sporks": [] | ||
}, | ||
"GenesisBlocks": { | ||
"Blocks": [] | ||
} | ||
}`) | ||
emptyHash = types.HexToHashPanic("30a9c36aa27d0b441eff8328a277e417ae0f1661f298f6376858f6819492811a") | ||
) | ||
|
||
func TestGenesisToFromJson(t *testing.T) { | ||
genesisFile := path.Join(t.TempDir(), "genesis.json") | ||
err := os.WriteFile(genesisFile, emptyGenesisJsonStr, 777) | ||
common.FailIfErr(t, err) | ||
|
||
config, err := ReadGenesisConfigFromFile(genesisFile) | ||
common.FailIfErr(t, err) | ||
common.ExpectString(t, config.GetGenesisMomentum().Hash.String(), emptyHash.String()) | ||
} | ||
|
||
func TestPartiallyWrittenFile(t *testing.T) { | ||
for i := 0; i < len(emptyGenesisJsonStr)-5; i += 1 { | ||
genesisFile := path.Join(t.TempDir(), "genesis.json") | ||
if err := os.WriteFile(genesisFile, emptyGenesisJsonStr[0:i], 777); err != nil { | ||
t.Fatal(err) | ||
} | ||
if _, err := ReadGenesisConfigFromFile(genesisFile); err != ErrIncompleteGenesisJson { | ||
t.Fatalf("Unexpected error %v `%v`", err, emptyGenesisJsonStr[0:i]) | ||
} | ||
} | ||
} | ||
|
||
func TestMalformedGenesis(t *testing.T) { | ||
genesisFile := path.Join(t.TempDir(), "genesis.json") | ||
if err := os.WriteFile(genesisFile, []byte(`{"a":"aaaa"]}`), 777); err != nil { | ||
t.Fatal(err) | ||
} | ||
if _, err := ReadGenesisConfigFromFile(genesisFile); err != ErrInvalidGenesisJson { | ||
t.Fatalf("Unexpected error %v", err) | ||
} | ||
} | ||
|
||
func TestEmptyGenesis(t *testing.T) { | ||
genesisFile := path.Join(t.TempDir(), "genesis.json") | ||
if err := os.WriteFile(genesisFile, []byte(`{}`), 777); err != nil { | ||
t.Fatal(err) | ||
} | ||
if _, err := ReadGenesisConfigFromFile(genesisFile); err != ErrInvalidGenesisConfig { | ||
t.Fatalf("Unexpected error %v", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package genesis | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/zenon-network/go-zenon/common" | ||
) | ||
|
||
func init() { | ||
if embeddedGenesis == nil && len(embeddedGenesisStr) != 0 { | ||
embeddedGenesis = new(GenesisConfig) | ||
common.DealWithErr(json.Unmarshal([]byte(embeddedGenesisStr), embeddedGenesis)) | ||
} | ||
} | ||
|
||
var ( | ||
embeddedGenesis *GenesisConfig | ||
) |
Oops, something went wrong.