failing test for send funds from contract
This commit is contained in:
parent
c4fc521629
commit
75e88969cb
|
@ -22,12 +22,7 @@ func (fas *FakeAppState) GetAccount(addr Word256) *Account {
|
|||
}
|
||||
|
||||
func (fas *FakeAppState) UpdateAccount(account *Account) {
|
||||
_, ok := fas.accounts[account.Address.String()]
|
||||
if !ok {
|
||||
panic(Fmt("Invalid account addr: %X", account.Address))
|
||||
} else {
|
||||
// Nothing to do
|
||||
}
|
||||
fas.accounts[account.Address.String()] = account
|
||||
}
|
||||
|
||||
func (fas *FakeAppState) RemoveAccount(account *Account) {
|
||||
|
|
|
@ -35,6 +35,7 @@ func makeBytes(n int) []byte {
|
|||
return b
|
||||
}
|
||||
|
||||
// Runs a basic loop
|
||||
func TestVM(t *testing.T) {
|
||||
ourVm := NewVM(newAppState(), newParams(), Zero256, nil)
|
||||
|
||||
|
@ -60,6 +61,7 @@ func TestVM(t *testing.T) {
|
|||
fmt.Println("Call took:", time.Since(start))
|
||||
}
|
||||
|
||||
// Tests the code for a subcurrency contract compiled by serpent
|
||||
func TestSubcurrency(t *testing.T) {
|
||||
st := newAppState()
|
||||
// Create accounts
|
||||
|
@ -89,6 +91,38 @@ func TestSubcurrency(t *testing.T) {
|
|||
|
||||
}
|
||||
|
||||
// Test sending tokens from a contract to another account
|
||||
func TestSendCall(t *testing.T) {
|
||||
fakeAppState := newAppState()
|
||||
ourVm := NewVM(fakeAppState, newParams(), Zero256, nil)
|
||||
|
||||
// Create accounts
|
||||
account1 := &Account{
|
||||
Address: Uint64ToWord256(100),
|
||||
}
|
||||
account2 := &Account{
|
||||
Address: Uint64ToWord256(101),
|
||||
}
|
||||
fakeAppState.UpdateAccount(account1)
|
||||
fakeAppState.UpdateAccount(account2)
|
||||
|
||||
addr := account1.Address.Postfix(20)
|
||||
gas1, gas2 := byte(0x1), byte(0x1)
|
||||
value := byte(0x69)
|
||||
inOff, inSize := byte(0x0), byte(0x0) // no call data
|
||||
retOff, retSize := byte(0x0), byte(0x20)
|
||||
// this is the code we want to run (send funds to an account and return)
|
||||
contractCode := []byte{0x60, retSize, 0x60, retOff, 0x60, inSize, 0x60, inOff, 0x60, value, 0x73}
|
||||
contractCode = append(contractCode, addr...)
|
||||
contractCode = append(contractCode, []byte{0x61, gas1, gas2, 0xf1, 0x60, 0x20, 0x60, 0x0, 0xf3}...)
|
||||
|
||||
var gas uint64 = 1000
|
||||
start := time.Now()
|
||||
output, err := ourVm.Call(account1, account2, contractCode, []byte{}, 0, &gas)
|
||||
fmt.Printf("Output: %v Error: %v\n", output, err)
|
||||
fmt.Println("Call took:", time.Since(start))
|
||||
}
|
||||
|
||||
/*
|
||||
// infinite loop
|
||||
code := []byte{0x5B, 0x60, 0x00, 0x56}
|
||||
|
|
4
vm/vm.go
4
vm/vm.go
|
@ -622,7 +622,7 @@ func (vm *VM) call(caller, callee *Account, code, input []byte, value uint64, ga
|
|||
stack.Push(res)
|
||||
pc += a
|
||||
dbg.Printf(" => 0x%X\n", res)
|
||||
stack.Print(10)
|
||||
//stack.Print(10)
|
||||
|
||||
case DUP1, DUP2, DUP3, DUP4, DUP5, DUP6, DUP7, DUP8, DUP9, DUP10, DUP11, DUP12, DUP13, DUP14, DUP15, DUP16:
|
||||
n := int(op - DUP1 + 1)
|
||||
|
@ -633,7 +633,7 @@ func (vm *VM) call(caller, callee *Account, code, input []byte, value uint64, ga
|
|||
n := int(op - SWAP1 + 2)
|
||||
stack.Swap(n)
|
||||
dbg.Printf(" => [%d] %X\n", n, stack.Peek())
|
||||
stack.Print(10)
|
||||
//stack.Print(10)
|
||||
|
||||
case LOG0, LOG1, LOG2, LOG3, LOG4:
|
||||
n := int(op - LOG0)
|
||||
|
|
Loading…
Reference in New Issue