Exemple #1
0
func TestRun2(t *testing.T) {
	ethutil.ReadConfig("")

	db, _ := ethdb.NewMemDatabase()
	state := NewState(ethutil.NewTrie(db, ""))

	script := Compile([]string{
		"PUSH", "0",
		"PUSH", "0",
		"TXSENDER",
		"PUSH", "10000000",
		"MKTX",
	})
	fmt.Println(ethutil.NewValue(script))

	tx := NewTransaction(ContractAddr, ethutil.Big("100000000000000000000000000000000000000000000000000"), script)
	fmt.Printf("contract addr %x\n", tx.Hash()[12:])
	contract := MakeContract(tx, state)
	vm := &Vm{}

	vm.Process(contract, state, RuntimeVars{
		address:     tx.Hash()[12:],
		blockNumber: 1,
		sender:      ethutil.FromHex("cd1722f3947def4cf144679da39c4c32bdc35681"),
		prevHash:    ethutil.FromHex("5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"),
		coinbase:    ethutil.FromHex("2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"),
		time:        1,
		diff:        big.NewInt(256),
		txValue:     tx.Value,
		txData:      tx.Data,
	})
}
Exemple #2
0
// cursor errors
func TestCursorErrors(t *testing.T) {
	memdb, _ := ethdb.NewMemDatabase()
	keyManager0 := NewDBKeyManager(memdb)
	err := keyManager0.Init("", 0, false)
	err = keyManager0.Init("", 1, false)
	if err == nil {
		t.Error("Expected cursor error")
	}
	err = keyManager0.SetCursor(1)
	if err == nil {
		t.Error("Expected cursor error")
	}
}
Exemple #3
0
func TestExportImport(t *testing.T) {
	memdb, _ := ethdb.NewMemDatabase()
	keyManager0 := NewDBKeyManager(memdb)
	err := keyManager0.Init("", 0, false)
	basedir0 := "/tmp/ethtest0"
	os.RemoveAll(basedir0)
	os.Mkdir(basedir0, 0777)
	keyManager0.Export(basedir0)

	keyManager1 := NewFileKeyManager(basedir0)
	err = keyManager1.Init("", 0, false)
	if err != nil {
		t.Error("Unexpected error: ", err)
	}
	fmt.Printf("keyRing: %v\n", keyManager0.KeyPair())
	fmt.Printf("keyRing: %v\n", keyManager1.KeyPair())
	if string(keyManager0.PrivateKey()) != string(keyManager1.PrivateKey()) {
		t.Error("Expected private keys %x, %x, to be identical via export to filestore basedir", keyManager0.PrivateKey(), keyManager1.PrivateKey())
	}
	path.Join("")

	// memdb, _ = ethdb.NewMemDatabase()
	// keyManager2 := NewDBKeyManager(memdb)
	// err = keyManager2.InitFromSecretsFile("", 0, path.Join(basedir0, "default.prv"))
	// if err != nil {
	// 	t.Error("Unexpected error: ", err)
	// }
	// if string(keyManager0.PrivateKey()) != string(keyManager2.PrivateKey()) {
	// 	t.Error("Expected private keys %s, %s, to be identical via export/import prv", keyManager0.PrivateKey(), keyManager1.PrivateKey())
	// }

	// memdb, _ = ethdb.NewMemDatabase()
	// keyManager3 := NewDBKeyManager(memdb)
	// err = keyManager3.InitFromSecretsFile("", 0, path.Join(basedir0, "default.mne"))
	// if err != nil {
	// 	t.Error("Unexpected error: ", err)
	// }
	// if string(keyManager0.PrivateKey()) != string(keyManager3.PrivateKey()) {
	// 	t.Error("Expected private keys %s, %s, to be identical via export/import mnemonic file", keyManager0.PrivateKey(), keyManager1.PrivateKey())
	// }
}
Exemple #4
0
func NewTestManager() *TestManager {
	ethutil.ReadConfig(".ethtest", "/tmp/ethtest", "ETH")

	db, err := ethdb.NewMemDatabase()
	if err != nil {
		fmt.Println("Could not create mem-db, failing")
		return nil
	}
	ethutil.Config.Db = db

	testManager := &TestManager{}
	testManager.reactor = ethreact.New()

	testManager.txPool = NewTxPool(testManager)
	testManager.blockChain = NewBlockChain(testManager)
	testManager.stateManager = NewStateManager(testManager)

	// Start the tx pool
	testManager.txPool.Start()

	return testManager
}
func TestVm(t *testing.T) {
	InitFees()
	ethutil.ReadConfig("")

	db, _ := ethdb.NewMemDatabase()
	ethutil.Config.Db = db
	bm := NewBlockManager(nil)

	block := bm.bc.genesisBlock
	script := Compile([]string{
		"PUSH",
		"1",
		"PUSH",
		"2",
	})
	tx := NewTransaction(ContractAddr, big.NewInt(200000000), script)
	addr := tx.Hash()[12:]
	bm.ApplyTransactions(block, []*Transaction{tx})

	tx2 := NewTransaction(addr, big.NewInt(1e17), nil)
	tx2.Sign([]byte("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
	bm.ApplyTransactions(block, []*Transaction{tx2})
}
Exemple #6
0
// test if persistence layer works
func TestDBKeyManager(t *testing.T) {
	memdb, _ := ethdb.NewMemDatabase()
	keyManager0 := NewDBKeyManager(memdb)
	err := keyManager0.Init("", 0, false)
	if err != nil {
		t.Error("Unexpected error: ", err)
	}
	keyManager1 := NewDBKeyManager(memdb)
	err = keyManager1.Init("", 0, false)
	if err != nil {
		t.Error("Unexpected error: ", err)
	}
	if string(keyManager0.PrivateKey()) != string(keyManager1.PrivateKey()) {
		t.Error("Expected private keys %x, %x, to be identical via db persistence", keyManager0.PrivateKey(), keyManager1.PrivateKey())
	}
	err = keyManager1.Init("", 0, true)
	if err != nil {
		t.Error("Unexpected error: ", err)
	}
	if string(keyManager0.PrivateKey()) == string(keyManager1.PrivateKey()) {
		t.Error("Expected private keys %x, %x, to be be different despite db persistence if force generate", keyManager0.PrivateKey(), keyManager1.PrivateKey())
	}
}
Exemple #7
0
func TestSnapshot(t *testing.T) {
	db, _ := ethdb.NewMemDatabase()
	ethutil.ReadConfig(".ethtest", "/tmp/ethtest", "")
	ethutil.Config.Db = db

	state := New(ethtrie.New(db, ""))

	stateObject := state.GetOrNewStateObject([]byte("aa"))

	stateObject.SetStorage(ethutil.Big("0"), ethutil.NewValue(42))

	snapshot := state.Copy()

	stateObject = state.GetStateObject([]byte("aa"))
	stateObject.SetStorage(ethutil.Big("0"), ethutil.NewValue(43))

	state.Set(snapshot)

	stateObject = state.GetStateObject([]byte("aa"))
	res := stateObject.GetStorage(ethutil.Big("0"))
	if !res.Cmp(ethutil.NewValue(42)) {
		t.Error("Expected storage 0 to be 42", res)
	}
}
Exemple #8
0
func NewConsole(s *eth.Ethereum) *Console {
	db, _ := ethdb.NewMemDatabase()
	trie := ethutil.NewTrie(db, "")

	return &Console{db: db, trie: trie, ethereum: s}
}