aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain/vm_test.go
diff options
context:
space:
mode:
authorMaran <maran.hidskes@gmail.com>2014-04-01 20:20:55 +0800
committerMaran <maran.hidskes@gmail.com>2014-04-01 20:20:55 +0800
commit0a8801082676d64f904cbb5b62c1159e0bbd7788 (patch)
tree05e9c4ea80d5e01cca53d583318f43606418a19e /ethchain/vm_test.go
parent5f49a659c36dbfb8c330ddc3d4565c19a9a936b5 (diff)
parent7277c420479239fbea78417e42c43ee0162c2728 (diff)
downloadgo-tangerine-0a8801082676d64f904cbb5b62c1159e0bbd7788.tar.gz
go-tangerine-0a8801082676d64f904cbb5b62c1159e0bbd7788.tar.zst
go-tangerine-0a8801082676d64f904cbb5b62c1159e0bbd7788.zip
Merge conflicts
Diffstat (limited to 'ethchain/vm_test.go')
-rw-r--r--ethchain/vm_test.go157
1 files changed, 53 insertions, 104 deletions
diff --git a/ethchain/vm_test.go b/ethchain/vm_test.go
index 047531e09..838f12f56 100644
--- a/ethchain/vm_test.go
+++ b/ethchain/vm_test.go
@@ -1,114 +1,17 @@
package ethchain
import (
- "bytes"
+ _ "bytes"
+ "fmt"
"github.com/ethereum/eth-go/ethdb"
"github.com/ethereum/eth-go/ethutil"
+ "github.com/obscuren/mutan"
"math/big"
+ "strings"
"testing"
)
/*
-
-func TestRun(t *testing.T) {
- InitFees()
-
- ethutil.ReadConfig("")
-
- db, _ := ethdb.NewMemDatabase()
- state := NewState(ethutil.NewTrie(db, ""))
-
- script := Compile([]string{
- "TXSENDER",
- "SUICIDE",
- })
-
- tx := NewTransaction(ContractAddr, big.NewInt(1e17), 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,
- })
-}
-
-func TestRun1(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,
- })
-}
-
-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,
- })
-}
-*/
-
-// XXX Full stack test
func TestRun3(t *testing.T) {
ethutil.ReadConfig("")
@@ -127,12 +30,12 @@ func TestRun3(t *testing.T) {
"PUSH", "0",
"RETURN",
})
- tx := NewTransaction(ContractAddr, ethutil.Big("100000000000000000000000000000000000000000000000000"), script)
+ tx := NewContractCreationTx(ethutil.Big("0"), ethutil.Big("1000"), script)
addr := tx.Hash()[12:]
contract := MakeContract(tx, state)
state.UpdateContract(contract)
- callerScript := ethutil.Compile(
+ callerScript := ethutil.Assemble(
"PUSH", 1337, // Argument
"PUSH", 65, // argument mem offset
"MSTORE",
@@ -149,7 +52,7 @@ func TestRun3(t *testing.T) {
"PUSH", 0,
"RETURN",
)
- callerTx := NewTransaction(ContractAddr, ethutil.Big("100000000000000000000000000000000000000000000000000"), callerScript)
+ callerTx := NewContractCreationTx(ethutil.Big("0"), ethutil.Big("1000"), callerScript)
// Contract addr as test address
account := NewAccount(ContractAddr, big.NewInt(10000000))
@@ -171,4 +74,50 @@ func TestRun3(t *testing.T) {
if bytes.Compare(ret, exp) != 0 {
t.Errorf("expected return value to be %v, got %v", exp, ret)
}
+}*/
+
+func TestRun4(t *testing.T) {
+ ethutil.ReadConfig("")
+
+ db, _ := ethdb.NewMemDatabase()
+ state := NewState(ethutil.NewTrie(db, ""))
+
+ asm, err := mutan.Compile(strings.NewReader(`
+ a = 10
+ b = 10
+ if a == b {
+ c = 10
+ if c == 10 {
+ d = 1000
+ e = 10
+ }
+ }
+
+ store[0] = 20
+ store[a] = 20
+ `), false)
+ if err != nil {
+ fmt.Println(err)
+ }
+ //asm = append(asm, "LOG")
+ fmt.Println(asm)
+
+ callerScript := ethutil.Assemble(asm...)
+ callerTx := NewContractCreationTx(ethutil.Big("0"), ethutil.Big("1000"), callerScript)
+
+ // Contract addr as test address
+ account := NewAccount(ContractAddr, big.NewInt(10000000))
+ callerClosure := NewClosure(account, MakeContract(callerTx, state), state, big.NewInt(1000000000), new(big.Int))
+
+ vm := NewVm(state, RuntimeVars{
+ origin: account.Address(),
+ blockNumber: 1,
+ prevHash: ethutil.FromHex("5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"),
+ coinbase: ethutil.FromHex("2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"),
+ time: 1,
+ diff: big.NewInt(256),
+ // XXX Tx data? Could be just an argument to the closure instead
+ txData: nil,
+ })
+ callerClosure.Call(vm, nil)
}