Skip to content

Commit

Permalink
fixing issue with blockID and contextual hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
DefinitelyNotAGoat committed Jan 19, 2021
1 parent 430d106 commit 800cc71
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
15 changes: 13 additions & 2 deletions rpc/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,24 @@ func (c *Client) extractContext(cycle int, blockID BlockID) (*resty.Response, st
if cycle != 0 {
resp, snapshot, err := c.Cycle(cycle)
if err != nil {
return resp, "", errors.Wrapf(err, "failed to get extract block ID for cycle '%d'", cycle)
return resp, "", errors.Wrapf(err, "failed to extract block ID for cycle '%d'", cycle)
}

return resp, snapshot.BlockHash, nil
}

return nil, blockID.ID(), nil
var hash string
if _, ok := blockID.(*BlockIDHash); !ok {
resp, blk, err := c.Block(blockID)
if err != nil {
return resp, "", errors.Wrapf(err, "failed to extract block hash for blockID '%s'", blockID.ID())
}
hash = blk.Hash
} else {
hash = blockID.ID()
}

return nil, hash, nil
}

/*
Expand Down
26 changes: 17 additions & 9 deletions rpc/fa12_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package rpc_test

import (
"fmt"
"net/http"
"net/http/httptest"
"strings"
"testing"

"github.com/goat-systems/go-tezos/v4/rpc"
Expand Down Expand Up @@ -513,11 +511,21 @@ func Test_GetFA12Allowance(t *testing.T) {
}

func Test_Temp(t *testing.T) {
str := strings.ReplaceAll(
"{\"contents\":[{\"kind\":\"transaction\",\"source\":\"tz1SUgyRB8T5jXgXAwS33pgRHAKrafyg87Yc\",\"fee\":\"0\",\"counter\":\"5010\",\"gas_limit\":\"1040000\",\"storage_limit\":\"60000\",\"amount\":\"0\",\"destination\":\"KT1CPuTzwC7h7uLXd5WQmpMFso1HxrLBUtpE\",\"parameters\":{\"entrypoint\":\"default\",\"value\":[{\"prim\":\"PUSH\",\"args\":[{\"prim\":\"mutez\"},{\"int\":\"0\"}]},{\"prim\":\"NONE\",\"args\":[{\"prim\":\"key_hash\"}]},{\"prim\":\"CREATE_CONTRACT\",\"args\":[[{\"prim\":\"parameter\",\"args\":[{\"prim\":\"nat\"}]},{\"prim\":\"storage\",\"args\":[{\"prim\":\"unit\"}]},{\"prim\":\"code\",\"args\":[[{\"prim\":\"FAILWITH\"}]]}]]},{\"prim\":\"DIP\",\"args\":[[{\"prim\":\"DIP\",\"args\":[[{\"prim\":\"LAMBDA\",\"args\":[{\"prim\":\"pair\",\"args\":[{\"prim\":\"address\"},{\"prim\":\"unit\"}]},{\"prim\":\"pair\",\"args\":[{\"prim\":\"list\",\"args\":[{\"prim\":\"operation\"}]},{\"prim\":\"unit\"}]},[{\"prim\":\"CAR\"},{\"prim\":\"CONTRACT\",\"args\":[{\"prim\":\"nat\"}]},{\"prim\":\"IF_NONE\",\"args\":[[{\"prim\":\"PUSH\",\"args\":[{\"prim\":\"string\"},{\"string\":\"a\"}]},{\"prim\":\"FAILWITH\"}],[]]},{\"prim\":\"PUSH\",\"args\":[{\"prim\":\"unit\"},{\"prim\":\"Unit\"}]},{\"prim\":\"PAIR\"},{\"prim\":\"DIP\",\"args\":[[{\"prim\":\"PUSH\",\"args\":[{\"prim\":\"address\"},{\"string\":\"KT1DrJV8vhkdLEj76h1H9Q4irZDqAkMPo1Qf\"}]},{\"prim\":\"CONTRACT\",\"args\":[{\"prim\":\"pair\",\"args\":[{\"prim\":\"unit\"},{\"prim\":\"contract\",\"args\":[{\"prim\":\"nat\"}]}]}],\"annots\":[\"%getTotalSupply\"]},{\"prim\":\"IF_NONE\",\"args\":[[{\"prim\":\"PUSH\",\"args\":[{\"prim\":\"string\"},{\"string\":\"b\"}]},{\"prim\":\"FAILWITH\"}],[]]},{\"prim\":\"PUSH\",\"args\":[{\"prim\":\"mutez\"},{\"int\":\"0\"}]}]]},{\"prim\":\"TRANSFER_TOKENS\"},{\"prim\":\"DIP\",\"args\":[[{\"prim\":\"NIL\",\"args\":[{\"prim\":\"operation\"}]}]]},{\"prim\":\"CONS\"},{\"prim\":\"DIP\",\"args\":[[{\"prim\":\"UNIT\"}]]},{\"prim\":\"PAIR\"}]]}]]},{\"prim\":\"APPLY\"},{\"prim\":\"DIP\",\"args\":[[{\"prim\":\"PUSH\",\"args\":[{\"prim\":\"address\"},{\"string\":\"KT1CPuTzwC7h7uLXd5WQmpMFso1HxrLBUtpE\"}]},{\"prim\":\"CONTRACT\",\"args\":[{\"prim\":\"lambda\",\"args\":[{\"prim\":\"unit\"},{\"prim\":\"pair\",\"args\":[{\"prim\":\"list\",\"args\":[{\"prim\":\"operation\"}]},{\"prim\":\"unit\"}]}]}]},{\"prim\":\"IF_NONE\",\"args\":[[{\"prim\":\"PUSH\",\"args\":[{\"prim\":\"string\"},{\"string\":\"c\"}]},{\"prim\":\"FAILWITH\"}],[]]},{\"prim\":\"PUSH\",\"args\":[{\"prim\":\"mutez\"},{\"int\":\"0\"}]}]]},{\"prim\":\"TRANSFER_TOKENS\"},{\"prim\":\"DIP\",\"args\":[[{\"prim\":\"NIL\",\"args\":[{\"prim\":\"operation\"}]}]]},{\"prim\":\"CONS\"}]]},{\"prim\":\"CONS\"},{\"prim\":\"DIP\",\"args\":[[{\"prim\":\"UNIT\"}]]},{\"prim\":\"PAIR\"}]},\"metadata\":{\"balance_updates\":[],\"operation_result\":{\"status\":\"backtracked\",\"storage\":{\"prim\":\"Unit\"},\"consumed_gas\":\"5198\",\"consumed_milligas\":\"5197947\",\"storage_size\":\"46\"},\"internal_operation_results\":[{\"kind\":\"origination\",\"source\":\"KT1CPuTzwC7h7uLXd5WQmpMFso1HxrLBUtpE\",\"nonce\":0,\"balance\":\"0\",\"script\":{\"code\":[{\"prim\":\"parameter\",\"args\":[{\"prim\":\"nat\"}]},{\"prim\":\"storage\",\"args\":[{\"prim\":\"unit\"}]},{\"prim\":\"code\",\"args\":[[{\"prim\":\"FAILWITH\"}]]}],\"storage\":{\"prim\":\"Unit\"}},\"result\":{\"status\":\"backtracked\",\"big_map_diff\":[],\"balance_updates\":[{\"kind\":\"contract\",\"contract\":\"tz1SUgyRB8T5jXgXAwS33pgRHAKrafyg87Yc\",\"change\":\"-8000\"},{\"kind\":\"contract\",\"contract\":\"tz1SUgyRB8T5jXgXAwS33pgRHAKrafyg87Yc\",\"change\":\"-64250\"}],\"originated_contracts\":[\"KT1KFvJWMcXi7sSuq5Pqe1bJXWTomndaAKw4\"],\"consumed_gas\":\"1595\",\"consumed_milligas\":\"1594348\",\"storage_size\":\"32\",\"paid_storage_size_diff\":\"32\"}},{\"kind\":\"transaction\",\"source\":\"KT1CPuTzwC7h7uLXd5WQmpMFso1HxrLBUtpE\",\"nonce\":1,\"amount\":\"0\",\"destination\":\"KT1CPuTzwC7h7uLXd5WQmpMFso1HxrLBUtpE\",\"parameters\":{\"entrypoint\":\"default\",\"value\":[{\"prim\":\"PUSH\",\"args\":[{\"prim\":\"address\"},{\"bytes\":\"017518c608448ed754b314e1b7acf9a3e8826e0a1a00\"}]},{\"prim\":\"PAIR\"},[{\"prim\":\"CAR\"},{\"prim\":\"CONTRACT\",\"args\":[{\"prim\":\"nat\"}]},{\"prim\":\"IF_NONE\",\"args\":[[{\"prim\":\"PUSH\",\"args\":[{\"prim\":\"string\"},{\"string\":\"a\"}]},{\"prim\":\"FAILWITH\"}],[]]},{\"prim\":\"PUSH\",\"args\":[{\"prim\":\"unit\"},{\"prim\":\"Unit\"}]},{\"prim\":\"PAIR\"},{\"prim\":\"DIP\",\"args\":[[{\"prim\":\"PUSH\",\"args\":[{\"prim\":\"address\"},{\"bytes\":\"0139c8ade2617663981fa2b87592c9ad92714d14c200\"}]},{\"prim\":\"CONTRACT\",\"args\":[{\"prim\":\"pair\",\"args\":[{\"prim\":\"unit\"},{\"prim\":\"contract\",\"args\":[{\"prim\":\"nat\"}]}]}],\"annots\":[\"%getTotalSupply\"]},{\"prim\":\"IF_NONE\",\"args\":[[{\"prim\":\"PUSH\",\"args\":[{\"prim\":\"string\"},{\"string\":\"b\"}]},{\"prim\":\"FAILWITH\"}],[]]},{\"prim\":\"PUSH\",\"args\":[{\"prim\":\"mutez\"},{\"int\":\"0\"}]}]]},{\"prim\":\"TRANSFER_TOKENS\"},{\"prim\":\"DIP\",\"args\":[[{\"prim\":\"NIL\",\"args\":[{\"prim\":\"operation\"}]}]]},{\"prim\":\"CONS\"},{\"prim\":\"DIP\",\"args\":[[{\"prim\":\"UNIT\"}]]},{\"prim\":\"PAIR\"}]]},\"result\":{\"status\":\"failed\",\"errors\":[{\"kind\":\"temporary\",\"id\":\"proto.007-PsDELPH1.michelson_v1.runtime_error\",\"contract_handle\":\"KT1CPuTzwC7h7uLXd5WQmpMFso1HxrLBUtpE\",\"contract_code\":[{\"prim\":\"parameter\",\"args\":[{\"prim\":\"lambda\",\"args\":[{\"prim\":\"unit\"},{\"prim\":\"pair\",\"args\":[{\"prim\":\"list\",\"args\":[{\"prim\":\"operation\"}]},{\"prim\":\"unit\"}]}]}]},{\"prim\":\"storage\",\"args\":[{\"prim\":\"unit\"}]},{\"prim\":\"code\",\"args\":[[{\"prim\":\"CAR\"},{\"prim\":\"UNIT\"},{\"prim\":\"EXEC\"}]]}]},{\"kind\":\"temporary\",\"id\":\"proto.007-PsDELPH1.michelson_v1.script_rejected\",\"location\":35,\"with\":{\"string\":\"b\"}}]}}]}}]}",
"\"",
"",
)
fmt.Println(str)
t.Fail()
r, err := rpc.New("https://mainnet-tezos.giganode.io/")
assert.Nil(t, err)

for i := 0; i < 1; i++ {
_, head, err := r.Block(&rpc.BlockIDHead{})
assert.Nil(t, err)

_, _, err = r.GetFA12Balance(rpc.GetFA12BalanceInput{
BlockID: &rpc.BlockIDHead{},
ChainID: head.ChainID,
Source: "tz3RDC3Jdn4j15J7bBHZd29EUee9gVB1CxD9",
FA12Contract: "KT1VYsVfmobT7rsMVivvZ4J8i3bPiqz12NaH",
OwnerAddress: "tz1dH4oxHPWuhzTfc7nPvus7AWyEbqE6YUyN",
ContractViewAddress: "KT1CPuTzwC7h7uLXd5WQmpMFso1HxrLBUtpE",
})
assert.Nil(t, err)
}
}

0 comments on commit 800cc71

Please sign in to comment.