Browse Source

Acc/X/Receive -> Acc/X/Call

pull/122/head
Jae Kwon 10 years ago
parent
commit
feeab6579b
5 changed files with 31 additions and 31 deletions
  1. +1
    -1
      rpc/test/client_ws_test.go
  2. +21
    -21
      state/permissions_test.go
  3. +2
    -2
      types/events.go
  4. +2
    -2
      vm/test/vm_test.go
  5. +5
    -5
      vm/vm.go

+ 1
- 1
rpc/test/client_ws_test.go View File

@ -190,7 +190,7 @@ func TestWSCallCall(t *testing.T) {
// susbscribe to the new contracts
amt = int64(10001)
eid1 := types.EventStringAccReceive(contractAddr1)
eid1 := types.EventStringAccCall(contractAddr1)
subscribe(t, con, eid1)
defer func() {
unsubscribe(t, con, eid1)


+ 21
- 21
state/permissions_test.go View File

@ -385,8 +385,8 @@ func TestCallPermission(t *testing.T) {
tx, _ = types.NewCallTx(blockCache, user[0].PubKey, caller1ContractAddr, nil, 100, 10000, 100)
tx.Sign(chainID, user[0])
// we need to subscribe to the Receive event to detect the exception
_, exception := execTxWaitEvent(t, blockCache, tx, types.EventStringAccReceive(caller1ContractAddr)) //
// we need to subscribe to the Call event to detect the exception
_, exception := execTxWaitEvent(t, blockCache, tx, types.EventStringAccCall(caller1ContractAddr)) //
if exception == "" {
t.Fatal("Expected exception")
}
@ -401,8 +401,8 @@ func TestCallPermission(t *testing.T) {
tx, _ = types.NewCallTx(blockCache, user[0].PubKey, caller1ContractAddr, nil, 100, 10000, 100)
tx.Sign(chainID, user[0])
// we need to subscribe to the Receive event to detect the exception
_, exception = execTxWaitEvent(t, blockCache, tx, types.EventStringAccReceive(caller1ContractAddr)) //
// we need to subscribe to the Call event to detect the exception
_, exception = execTxWaitEvent(t, blockCache, tx, types.EventStringAccCall(caller1ContractAddr)) //
if exception != "" {
t.Fatal("Unexpected exception:", exception)
}
@ -431,8 +431,8 @@ func TestCallPermission(t *testing.T) {
tx, _ = types.NewCallTx(blockCache, user[0].PubKey, caller2ContractAddr, nil, 100, 10000, 100)
tx.Sign(chainID, user[0])
// we need to subscribe to the Receive event to detect the exception
_, exception = execTxWaitEvent(t, blockCache, tx, types.EventStringAccReceive(caller1ContractAddr)) //
// we need to subscribe to the Call event to detect the exception
_, exception = execTxWaitEvent(t, blockCache, tx, types.EventStringAccCall(caller1ContractAddr)) //
if exception == "" {
t.Fatal("Expected exception")
}
@ -449,8 +449,8 @@ func TestCallPermission(t *testing.T) {
tx, _ = types.NewCallTx(blockCache, user[0].PubKey, caller2ContractAddr, nil, 100, 10000, 100)
tx.Sign(chainID, user[0])
// we need to subscribe to the Receive event to detect the exception
_, exception = execTxWaitEvent(t, blockCache, tx, types.EventStringAccReceive(caller1ContractAddr)) //
// we need to subscribe to the Call event to detect the exception
_, exception = execTxWaitEvent(t, blockCache, tx, types.EventStringAccCall(caller1ContractAddr)) //
if exception != "" {
t.Fatal("Unexpected exception", exception)
}
@ -519,8 +519,8 @@ func TestCreatePermission(t *testing.T) {
// A single input, having the permission, should succeed
tx, _ = types.NewCallTx(blockCache, user[0].PubKey, contractAddr, createCode, 100, 100, 100)
tx.Sign(chainID, user[0])
// we need to subscribe to the Receive event to detect the exception
_, exception := execTxWaitEvent(t, blockCache, tx, types.EventStringAccReceive(contractAddr)) //
// we need to subscribe to the Call event to detect the exception
_, exception := execTxWaitEvent(t, blockCache, tx, types.EventStringAccCall(contractAddr)) //
if exception == "" {
t.Fatal("expected exception")
}
@ -535,8 +535,8 @@ func TestCreatePermission(t *testing.T) {
// A single input, having the permission, should succeed
tx, _ = types.NewCallTx(blockCache, user[0].PubKey, contractAddr, createCode, 100, 100, 100)
tx.Sign(chainID, user[0])
// we need to subscribe to the Receive event to detect the exception
_, exception = execTxWaitEvent(t, blockCache, tx, types.EventStringAccReceive(contractAddr)) //
// we need to subscribe to the Call event to detect the exception
_, exception = execTxWaitEvent(t, blockCache, tx, types.EventStringAccCall(contractAddr)) //
if exception != "" {
t.Fatal("unexpected exception", exception)
}
@ -562,8 +562,8 @@ func TestCreatePermission(t *testing.T) {
// this should call the 0 address but not create ...
tx, _ = types.NewCallTx(blockCache, user[0].PubKey, contractAddr, createCode, 100, 10000, 100)
tx.Sign(chainID, user[0])
// we need to subscribe to the Receive event to detect the exception
_, exception = execTxWaitEvent(t, blockCache, tx, types.EventStringAccReceive(zeroAddr)) //
// we need to subscribe to the Call event to detect the exception
_, exception = execTxWaitEvent(t, blockCache, tx, types.EventStringAccCall(zeroAddr)) //
if exception != "" {
t.Fatal("unexpected exception", exception)
}
@ -813,8 +813,8 @@ func TestCreateAccountPermission(t *testing.T) {
txCall, _ := types.NewCallTx(blockCache, user[0].PubKey, caller1ContractAddr, nil, 100, 10000, 100)
txCall.Sign(chainID, user[0])
// we need to subscribe to the Receive event to detect the exception
_, exception := execTxWaitEvent(t, blockCache, txCall, types.EventStringAccReceive(caller1ContractAddr)) //
// we need to subscribe to the Call event to detect the exception
_, exception := execTxWaitEvent(t, blockCache, txCall, types.EventStringAccCall(caller1ContractAddr)) //
if exception == "" {
t.Fatal("Expected exception")
}
@ -828,8 +828,8 @@ func TestCreateAccountPermission(t *testing.T) {
txCall, _ = types.NewCallTx(blockCache, user[0].PubKey, caller1ContractAddr, nil, 100, 10000, 100)
txCall.Sign(chainID, user[0])
// we need to subscribe to the Receive event to detect the exception
_, exception = execTxWaitEvent(t, blockCache, txCall, types.EventStringAccReceive(caller1ContractAddr)) //
// we need to subscribe to the Call event to detect the exception
_, exception = execTxWaitEvent(t, blockCache, txCall, types.EventStringAccCall(caller1ContractAddr)) //
if exception != "" {
t.Fatal("Unexpected exception", exception)
}
@ -1048,7 +1048,7 @@ func TestSNativeTx(t *testing.T) {
var ExceptionTimeOut = "timed out waiting for event"
// run ExecTx and wait for the Receive event on given addr
// run ExecTx and wait for the Call event on given addr
// returns the msg data and an error/exception
func execTxWaitEvent(t *testing.T, blockCache *BlockCache, tx types.Tx, eventid string) (interface{}, string) {
evsw := events.NewEventSwitch()
@ -1109,8 +1109,8 @@ func testSNativeCALL(t *testing.T, expectPass bool, blockCache *BlockCache, doug
addr = doug.Address
tx, _ := types.NewCallTx(blockCache, user[0].PubKey, addr, data, 100, 10000, 100)
tx.Sign(chainID, user[0])
fmt.Println("subscribing to", types.EventStringAccReceive(snativeAddress))
ev, exception := execTxWaitEvent(t, blockCache, tx, types.EventStringAccReceive(snativeAddress))
fmt.Println("subscribing to", types.EventStringAccCall(snativeAddress))
ev, exception := execTxWaitEvent(t, blockCache, tx, types.EventStringAccCall(snativeAddress))
if exception == ExceptionTimeOut {
t.Fatal("Timed out waiting for event")
}


+ 2
- 2
types/events.go View File

@ -14,8 +14,8 @@ func EventStringAccOutput(addr []byte) string {
return fmt.Sprintf("Acc/%X/Output", addr)
}
func EventStringAccReceive(addr []byte) string {
return fmt.Sprintf("Acc/%X/Receive", addr)
func EventStringAccCall(addr []byte) string {
return fmt.Sprintf("Acc/%X/Call", addr)
}
func EventStringLogEvent(addr []byte) string {


+ 2
- 2
vm/test/vm_test.go View File

@ -151,14 +151,14 @@ func TestSendCall(t *testing.T) {
}
}
// subscribes to an AccReceive, runs the vm, returns the exception
// subscribes to an AccCall, runs the vm, returns the exception
func runVMWaitEvents(t *testing.T, ourVm *VM, caller, callee *Account, subscribeAddr, contractCode []byte, gas int64) string {
// we need to catch the event from the CALL to check for exceptions
evsw := events.NewEventSwitch()
evsw.Start()
ch := make(chan interface{})
fmt.Printf("subscribe to %x\n", subscribeAddr)
evsw.AddListenerForEvent("test", types.EventStringAccReceive(subscribeAddr), func(msg interface{}) {
evsw.AddListenerForEvent("test", types.EventStringAccCall(subscribeAddr), func(msg interface{}) {
ch <- msg
})
evc := events.NewEventCache(evsw)


+ 5
- 5
vm/vm.go View File

@ -95,10 +95,10 @@ func HasPermission(appState AppState, acc *Account, perm ptypes.PermFlag) bool {
return v
}
func (vm *VM) fireEvent(exception *string, output *[]byte, caller, callee *Account, input []byte, value int64, gas *int64) {
func (vm *VM) fireCallEvent(exception *string, output *[]byte, caller, callee *Account, input []byte, value int64, gas *int64) {
// fire the post call event (including exception if applicable)
if vm.evc != nil {
vm.evc.FireEvent(types.EventStringAccReceive(callee.Address.Postfix(20)), types.EventMsgCall{
vm.evc.FireEvent(types.EventStringAccCall(callee.Address.Postfix(20)), types.EventMsgCall{
&types.CallData{caller.Address.Postfix(20), callee.Address.Postfix(20), input, value, *gas},
vm.origin.Postfix(20),
vm.txid,
@ -116,7 +116,7 @@ func (vm *VM) Call(caller, callee *Account, code, input []byte, value int64, gas
exception := new(string)
// fire the post call event (including exception if applicable)
defer vm.fireEvent(exception, &output, caller, callee, input, value, gas)
defer vm.fireCallEvent(exception, &output, caller, callee, input, value, gas)
if err = transfer(caller, callee, value); err != nil {
*exception = err.Error()
@ -754,12 +754,12 @@ func (vm *VM) call(caller, callee *Account, code, input []byte, value int64, gas
// Native contract
ret, err = nativeContract(vm.appState, callee, args, &gasLimit)
// for now we fire the Receive event. maybe later we'll fire more particulars
// for now we fire the Call event. maybe later we'll fire more particulars
var exception string
if err != nil {
exception = err.Error()
}
vm.fireEvent(&exception, &ret, callee, &Account{Address: addr}, args, value, gas)
vm.fireCallEvent(&exception, &ret, callee, &Account{Address: addr}, args, value, gas)
} else {
// EVM contract
if ok = useGas(gas, GasGetAccount); !ok {


Loading…
Cancel
Save