From b267e649aede3f63200142d06aba51b8a8e8ced0 Mon Sep 17 00:00:00 2001 From: Quint Daenen Date: Fri, 22 Mar 2024 10:10:02 +0100 Subject: [PATCH] Add effective canister ids to mgmt canister interface. --- agent.go | 15 +- agent_test.go | 27 ++ candid/idl/decode.go | 2 +- client.go | 17 + didc | 0 ic/ic/actor.mo | 88 ---- ic/ic/agent_test.go | 860 --------------------------------------- ic/ic/types.mo | 64 --- ic/testdata/gen.go | 2 + logger.go | 9 + {ic/ic => mgmt}/agent.go | 151 ++----- request_test.go | 13 + status_test.go | 4 +- 13 files changed, 119 insertions(+), 1133 deletions(-) create mode 100644 didc delete mode 100755 ic/ic/actor.mo delete mode 100755 ic/ic/agent_test.go delete mode 100755 ic/ic/types.mo create mode 100644 logger.go rename {ic/ic => mgmt}/agent.go (87%) diff --git a/agent.go b/agent.go index d73fd44..8a888ae 100644 --- a/agent.go +++ b/agent.go @@ -44,6 +44,7 @@ type Agent struct { identity identity.Identity ingressExpiry time.Duration rootKey []byte + logger Logger } // New returns a new Agent based on the given configuration. @@ -56,13 +57,17 @@ func New(cfg Config) (*Agent, error) { if cfg.Identity != nil { id = cfg.Identity } + var logger Logger = &defaultLogger{} + if cfg.Logger != nil { + logger = cfg.Logger + } ccfg := ClientConfig{ Host: icp0, } if cfg.ClientConfig != nil { ccfg = *cfg.ClientConfig } - client := NewClient(ccfg) + client := NewClientWithLogger(ccfg, logger) rootKey, _ := hex.DecodeString(certificate.RootKey) if cfg.FetchRootKey { status, err := client.Status() @@ -76,6 +81,7 @@ func New(cfg Config) (*Agent, error) { identity: id, ingressExpiry: cfg.IngressExpiry, rootKey: rootKey, + logger: logger, }, nil } @@ -100,6 +106,7 @@ func (a Agent) Call(canisterID principal.Principal, methodName string, args []an if err != nil { return err } + a.logger.Printf("[AGENT] CALL %s %s", canisterID, methodName) if _, err := a.call(canisterID, data); err != nil { return err } @@ -191,6 +198,7 @@ func (a Agent) Query(canisterID principal.Principal, methodName string, args []a if err != nil { return err } + a.logger.Printf("[AGENT] QUERY %s %s", canisterID, methodName) resp, err := a.query(canisterID, data) if err != nil { return err @@ -209,6 +217,7 @@ func (a Agent) Query(canisterID principal.Principal, methodName string, args []a // RequestStatus returns the status of the request with the given ID. func (a Agent) RequestStatus(canisterID principal.Principal, requestID RequestID) ([]byte, certificate.Node, error) { + a.logger.Printf("[AGENT] REQUEST STATUS %s", requestID) path := [][]byte{[]byte("request_status"), requestID[:]} c, err := a.readStateCertificate(canisterID, [][][]byte{path}) if err != nil { @@ -251,6 +260,7 @@ func (a Agent) poll(canisterID principal.Principal, requestID RequestID, delay, for { select { case <-ticker.C: + a.logger.Printf("[AGENT] POLL %s", requestID) data, node, err := a.RequestStatus(canisterID, requestID) if err != nil { return nil, err @@ -301,7 +311,7 @@ func (a Agent) readStateCertificate(canisterID principal.Principal, paths [][][] if err != nil { return nil, err } - + a.logger.Printf("[AGENT] READ STATE %s", canisterID) resp, err := a.readState(canisterID, data) if err != nil { return nil, err @@ -328,4 +338,5 @@ type Config struct { IngressExpiry time.Duration ClientConfig *ClientConfig FetchRootKey bool + Logger Logger } diff --git a/agent_test.go b/agent_test.go index 409b74d..eaaa7fe 100644 --- a/agent_test.go +++ b/agent_test.go @@ -6,9 +6,11 @@ import ( "encoding/json" "fmt" "github.com/aviate-labs/agent-go" + "github.com/aviate-labs/agent-go/candid/idl" "github.com/aviate-labs/agent-go/ic" "github.com/aviate-labs/agent-go/ic/icpledger" "github.com/aviate-labs/agent-go/identity" + "github.com/aviate-labs/agent-go/mgmt" "github.com/aviate-labs/agent-go/principal" "testing" ) @@ -67,6 +69,25 @@ func Example_query() { // 0 } +func TestAgent_Call(t *testing.T) { + a, err := mgmt.NewAgent(agent.Config{ + Logger: &testLogger{}, + }) + if err != nil { + t.Fatal(err) + } + r, err := a.BitcoinGetBalanceQuery(mgmt.BitcoinGetBalanceQueryArgs{ + Address: "bc1qruu3xmfrt4nzkxax3lpxfmjega87jr3vqcwjn9", + Network: mgmt.BitcoinNetwork{ + Mainnet: new(idl.Null), + }, + }) + if err != nil { + t.Fatal(err) + } + fmt.Println(r) +} + func TestICPLedger_queryBlocks(t *testing.T) { a, err := icpledger.NewAgent(ic.LEDGER_PRINCIPAL, agent.DefaultConfig) if err != nil { @@ -79,3 +100,9 @@ func TestICPLedger_queryBlocks(t *testing.T) { t.Fatal(err) } } + +type testLogger struct{} + +func (l *testLogger) Printf(format string, v ...interface{}) { + fmt.Printf("[TEST]"+format+"\n", v...) +} diff --git a/candid/idl/decode.go b/candid/idl/decode.go index 3d1ad6a..7bf3b9e 100644 --- a/candid/idl/decode.go +++ b/candid/idl/decode.go @@ -269,7 +269,7 @@ func Decode(bs []byte) ([]Type, []any, error) { } f, ok := v.(*FunctionType) if !ok { - fmt.Println(reflect.TypeOf(v)) + return nil, nil, fmt.Errorf("invalid method type: %s", reflect.TypeOf(v)) } methods = append(methods, Method{ Name: string(name), diff --git a/client.go b/client.go index d54cb29..0901d56 100644 --- a/client.go +++ b/client.go @@ -16,6 +16,7 @@ import ( type Client struct { client http.Client config ClientConfig + logger Logger } // NewClient creates a new client based on the given configuration. @@ -23,6 +24,19 @@ func NewClient(cfg ClientConfig) Client { return Client{ client: http.Client{}, config: cfg, + logger: &defaultLogger{}, + } +} + +// NewClientWithLogger creates a new client based on the given configuration and logger. +func NewClientWithLogger(cfg ClientConfig, logger Logger) Client { + if logger == nil { + logger = &defaultLogger{} + } + return Client{ + client: http.Client{}, + config: cfg, + logger: logger, } } @@ -38,6 +52,7 @@ func (c Client) Status() (*Status, error) { func (c Client) call(canisterID principal.Principal, data []byte) ([]byte, error) { u := c.url(fmt.Sprintf("/api/v2/canister/%s/call", canisterID.Encode())) + c.logger.Printf("[CLIENT] CALL %s", u) resp, err := c.client.Post(u, "application/cbor", bytes.NewBuffer(data)) if err != nil { return nil, err @@ -59,6 +74,7 @@ func (c Client) call(canisterID principal.Principal, data []byte) ([]byte, error } func (c Client) get(path string) ([]byte, error) { + c.logger.Printf("[CLIENT] GET %s", c.url(path)) resp, err := c.client.Get(c.url(path)) if err != nil { return nil, err @@ -68,6 +84,7 @@ func (c Client) get(path string) ([]byte, error) { func (c Client) post(path string, canisterID principal.Principal, data []byte) ([]byte, error) { u := c.url(fmt.Sprintf("/api/v2/canister/%s/%s", canisterID.Encode(), path)) + c.logger.Printf("[CLIENT] POST %s", u) resp, err := c.client.Post(u, "application/cbor", bytes.NewBuffer(data)) if err != nil { return nil, err diff --git a/didc b/didc new file mode 100644 index 0000000..e69de29 diff --git a/ic/ic/actor.mo b/ic/ic/actor.mo deleted file mode 100755 index bfc672e..0000000 --- a/ic/ic/actor.mo +++ /dev/null @@ -1,88 +0,0 @@ -// Do NOT edit this file. It was automatically generated by https://github.com/aviate-labs/agent-go. -import T "types"; - -import { principalOfBlob } = "mo:⛔"; - -actor class _ic() : async actor {} { - public shared func create_canister(_arg0 : T.CreateCanisterArgs) : async (T.CreateCanisterResult) { - ({ canister_id = principalOfBlob("x869AF7A6140D470862C22E5F4C779F515D2190E37D31EEC1BDFD5BBCE1B03FA0") }) - }; - public shared func update_settings(_arg0 : T.UpdateSettingsArgs) : async () { - () - }; - public shared func upload_chunk(_arg0 : T.UploadChunkArgs) : async (T.UploadChunkResult) { - ({ hash = "x869AF7A6140D470862C22E5F4C779F515D2190E37D31EEC1BDFD5BBCE1B03FA0" }) - }; - public shared func clear_chunk_store(_arg0 : T.ClearChunkStoreArgs) : async () { - () - }; - public shared func stored_chunks(_arg0 : T.StoredChunksArgs) : async (T.StoredChunksResult) { - ([ { hash = "x0862C22E5F4C779F515D2190E37D31EEC1BDFD5BBCE1B03FA00DA2FE1A254CA2" }, { hash = "x3D005FB6E22DF7BA41EBE7B21A1C13F932DE5C88E3F7CBBA21D83DB973446660" }, { hash = "x1A2AA3EF195DD53147822C629DF98B40FE3A93E721D185BD47D7EEE55135BB08" }, { hash = "x88544768FAFB19D706D81F6BD23CB10726A014187038BCE35CB2F3ECCB7DD75F" } ]) - }; - public shared func install_code(_arg0 : T.InstallCodeArgs) : async () { - () - }; - public shared func install_chunked_code(_arg0 : T.InstallChunkedCodeArgs) : async () { - () - }; - public shared func uninstall_code(_arg0 : T.UninstallCodeArgs) : async () { - () - }; - public shared func start_canister(_arg0 : T.StartCanisterArgs) : async () { - () - }; - public shared func stop_canister(_arg0 : T.StopCanisterArgs) : async () { - () - }; - public shared func canister_status(_arg0 : T.CanisterStatusArgs) : async (T.CanisterStatusResult) { - ({ status = #running; settings = { controllers = [ principalOfBlob("x9F515D2190E37D31EEC1BDFD5BBCE1B03FA00DA2FE1A254CA23FD9613D005FB6"), principalOfBlob("xBA41EBE7B21A1C13F932DE5C88E3F7CBBA21D83DB97344666081C6741A2AA3EF"), principalOfBlob("x3147822C629DF98B40FE3A93E721D185BD47D7EEE55135BB0860874988544768"), principalOfBlob("xD706D81F6BD23CB10726A014187038BCE35CB2F3ECCB7DD75F4647487E926B57"), principalOfBlob("x1AB600EF4AE294D7E2D2267FA77832A886DE6E4B72F4197FF183421A910092C0"), principalOfBlob("x472B7A3158CE1700CC21E6E714AF1108697FFC6D45094AEDFBE2A29AD1939D09"), principalOfBlob("x30190C629CD14D0FC80915A4320DA282A98A18083753F3DE7592A2198D6B99C8"), principalOfBlob("xEC8A4F529F93BB58C59A87D62A7717691617B8B442AFB32C31DF22DF57966FEA") ]; compute_allocation = 7181374305377412901; memory_allocation = 8483647216729911020; freezing_threshold = 14994143942249040469; reserved_cycles_limit = 14039119793643782529 }; module_hash = ?"xB34811D335EB789A5543731482481F165AAA1560662B8E9D514E23991BA4248F"; memory_size = 16803621580220603980; cycles = 9736605414087480391; reserved_cycles = 14670472641987634058; idle_cycles_burned_per_day = 2674853784875525116 }) - }; - public shared func canister_info(_arg0 : T.CanisterInfoArgs) : async (T.CanisterInfoResult) { - ({ total_num_changes = 15656497011928570502; recent_changes = [ { timestamp_nanos = 14519010981886906783; canister_version = 3800013330962312753; origin = #from_canister({ canister_id = principalOfBlob("x1A254CA23FD9613D005FB6E22DF7BA41EBE7B21A1C13F932DE5C88E3F7CBBA21"); canister_version = ?13363524253285500019 }); details = #code_deployment({ mode = #install; module_hash = "x8B40FE3A93E721D185BD47D7EEE55135BB0860874988544768FAFB19D706D81F" }) }, { timestamp_nanos = 18045950183738836913; canister_version = 5831303564926106680; origin = #from_canister({ canister_id = principalOfBlob("x7E926B574D40DD1AB600EF4AE294D7E2D2267FA77832A886DE6E4B72F4197FF1"); canister_version = ?15832102157618905233 }); details = #controllers_change({ controllers = [ principalOfBlob("x1108697FFC6D45094AEDFBE2A29AD1939D09B4D94630190C629CD14D0FC80915"), principalOfBlob("xA282A98A18083753F3DE7592A2198D6B99C8F949A2EC8A4F529F93BB58C59A87"), principalOfBlob("x17691617B8B442AFB32C31DF22DF57966FEA580488256723D7E15DA9ECEEEA00"), principalOfBlob("x554AD41C79E61581014BE311F9D4B34811D335EB789A5543731482481F165AAA"), principalOfBlob("x2B8E9D514E23991BA4248FFA389E4C1E233DCC74324754D490095F1F8A63C2F0"), principalOfBlob("xFC639D6958FD1EA1E5B346359864D5BE44010FF463BBE3FC7A6969524896FE46"), principalOfBlob("xC23A172820B58468A0172ED6160AAAD5CD022CD31A758DAED770BD742E48D130"), principalOfBlob("xF8C698FD6E1D95443E119353DE510A61BC14E1216A7498623DB922273C26F534") ] }) }, { timestamp_nanos = 10541212000563527943; canister_version = 2689134793603183504; origin = #from_canister({ canister_id = principalOfBlob("xFD0E74B0990E0078D2B236027D6B7FC5C5F87878D58678F82484F4E75D2F951C"); canister_version = ?14834280829257491391 }); details = #creation({ controllers = [ principalOfBlob("xD92065148671911683101A133588AE791A21EC626F4BF9C04EFC0618773EAA16"), principalOfBlob("xE6C4C477AF447EC1D59F4DE45FA855620A308ACE5E7985E23EEC83B6DE9E7A45"), principalOfBlob("x5C4698C942208D3A6C38A387F9DD652E440339C1E0698E3FF7D098E5ADF0DE50"), principalOfBlob("xEC36CC81E040F2487088112A24F71279CFCEF6E28B80B686F9CB5EF661C10795"), principalOfBlob("xDA90DE1A63AF6E2336D10DD0AA6B73AD0792645EEBDDE279F464613D0D3FEEFD"), principalOfBlob("xD7273B138C7BA77B24762E9719827530A112A44E62E38FBB862EA149FDD66F9A") ] }) }, { timestamp_nanos = 14116231344195082928; canister_version = 4523606734605955336; origin = #from_user({ user_id = principalOfBlob("x9A1B4EEAF85713EE92E855F1BEE87F3FE35C84FDD06850DAC8F040ACD17D576A") }); details = #code_deployment({ mode = #reinstall; module_hash = "x25B00214F7C6B8BA3F69EC1FBD8BC9CC09D1B95EB57A8B1D022B04E7DCDFA58E" }) }, { timestamp_nanos = 3481921817742942786; canister_version = 9192667871694660610; origin = #from_canister({ canister_id = principalOfBlob("x3A16C322D334F8042ED922291CB854D60A33E746222A023EA5020B7D41655642"); canister_version = ?10449616418252478675 }); details = #controllers_change({ controllers = [ principalOfBlob("xC4ED20EBB0444E73617ECA0ABBC443EDF0163E4F4B23AF8CCCD2A3190579A59D") ] }) }, { timestamp_nanos = 14686404346102099380; canister_version = 2250618464655299498; origin = #from_user({ user_id = principalOfBlob("x374DA7D7B5F718177360AE769AE8F5B227269DA9D837857A4238F0C809FCF065") }); details = #code_uninstall }, { timestamp_nanos = 9568659421456693105; canister_version = 848519729038390968; origin = #from_user({ user_id = principalOfBlob("xEC395D74A4E4E610A0DCE6AD5E24D0FC4A81F68D8B9F8E9A874E3492BAC55757") }); details = #controllers_change({ controllers = [ principalOfBlob("xC1B42179ADA7FAB19B81214F32C5CB41BA44AEB1B0A285FCA96DC7529E31667A"), principalOfBlob("x6F4A3BF6B1C5F5B4DA96F373CE56A20DF3491E602A349325524A8D03331CE083") ] }) }, { timestamp_nanos = 5550019485348043196; canister_version = 12412919251015282992; origin = #from_user({ user_id = principalOfBlob("xCDE635272898479BC9935BEF0A6C51CEB1EED82A478AFE75A02F087067D12A9F") }); details = #code_deployment({ mode = #upgrade; module_hash = "x75A4DDAF64344788F0A5E08AEF31457D2629F301DF60AB8177C3FFAC498B9074" }) } ]; module_hash = ?"x17E7C82BF52CA609FA741633E6A4BF64B753791583EE9B0C78A073DE0E38B9BD"; controllers = [ principalOfBlob("xEB51862AB2B4A466C1D3F906E8986CF0284AD909DE18D8F5933BFAE314FFEABD"), principalOfBlob("xDE3ACE7BC63AABA7506A20E9C93555300ABC7CD8ED3EB286AEDCB24CAB0812C6"), principalOfBlob("x9A18B820BE6164576BBE8F88910CBF148176C3B86DDA0B3E165458750059B587"), principalOfBlob("xD6BFE31BFBCAF99A799D55B2CA3E017C90144C96C3DE646E93B8D6136B7D83E0") ] }) - }; - public shared func delete_canister(_arg0 : T.DeleteCanisterArgs) : async () { - () - }; - public shared func deposit_cycles(_arg0 : T.DepositCyclesArgs) : async () { - () - }; - public shared func raw_rand() : async (T.RawRandResult) { - ("x869AF7A6140D470862C22E5F4C779F515D2190E37D31EEC1BDFD5BBCE1B03FA0") - }; - public shared func http_request(_arg0 : T.HttpRequestArgs) : async (T.HttpRequestResult) { - ({ status = 15656497011928570502; headers = [ { name = "14519010981886906783"; value = "3800013330962312753" }, { name = "6412741098828968161"; value = "11484699392100541722" }, { name = "17507512528171630653"; value = "17445848412223914426" }, { name = "2946348513676687635"; value = "628601621483015159" }, { name = "13363524253285500019"; value = "17786224669345655322" }, { name = "11671532954286442289"; value = "18312172179401097355" }, { name = "11810108206237976017"; value = "8739665398422254929" }, { name = "6996900549006677128"; value = "11041931743943198423" } ]; body = "xB10726A014187038BCE35CB2F3ECCB7DD75F4647487E926B574D40DD1AB600EF" }) - }; - public shared func ecdsa_public_key(_arg0 : T.EcdsaPublicKeyArgs) : async (T.EcdsaPublicKeyResult) { - ({ public_key = "x869AF7A6140D470862C22E5F4C779F515D2190E37D31EEC1BDFD5BBCE1B03FA0"; chain_code = "x1A254CA23FD9613D005FB6E22DF7BA41EBE7B21A1C13F932DE5C88E3F7CBBA21" }) - }; - public shared func sign_with_ecdsa(_arg0 : T.SignWithEcdsaArgs) : async (T.SignWithEcdsaResult) { - ({ signature = "x869AF7A6140D470862C22E5F4C779F515D2190E37D31EEC1BDFD5BBCE1B03FA0" }) - }; - public shared func bitcoin_get_balance(_arg0 : T.BitcoinGetBalanceArgs) : async (T.BitcoinGetBalanceResult) { - (15656497011928570502) - }; - public query func bitcoin_get_balance_query(_arg0 : T.BitcoinGetBalanceQueryArgs) : async (T.BitcoinGetBalanceQueryResult) { - (15656497011928570502) - }; - public shared func bitcoin_get_utxos(_arg0 : T.BitcoinGetUtxosArgs) : async (T.BitcoinGetUtxosResult) { - ({ utxos = [ { outpoint = { txid = "x0862C22E5F4C779F515D2190E37D31EEC1BDFD5BBCE1B03FA00DA2FE1A254CA2"; vout = 2840997408 }; value = 17445848412223914426; height = 118915440 }, { outpoint = { txid = "xF7CBBA21D83DB97344666081C6741A2AA3EF195DD53147822C629DF98B40FE3A"; vout = 3953357992 }; value = 8739665398422254929; height = 3378598018 }, { outpoint = { txid = "xD706D81F6BD23CB10726A014187038BCE35CB2F3ECCB7DD75F4647487E926B57"; vout = 2056624229 }; value = 1763343418669589207; height = 3388535713 }, { outpoint = { txid = "xF4197FF183421A910092C007EDB6472B7A3158CE1700CC21E6E714AF1108697F"; vout = 92794092 }; value = 4919859010227508177; height = 2337925836 } ]; tip_block_hash = "x0FC80915A4320DA282A98A18083753F3DE7592A2198D6B99C8F949A2EC8A4F52"; tip_height = 2903633966; next_page = ?"x17691617B8B442AFB32C31DF22DF57966FEA580488256723D7E15DA9ECEEEA00" }) - }; - public query func bitcoin_get_utxos_query(_arg0 : T.BitcoinGetUtxosQueryArgs) : async (T.BitcoinGetUtxosQueryResult) { - ({ utxos = [ { outpoint = { txid = "x0862C22E5F4C779F515D2190E37D31EEC1BDFD5BBCE1B03FA00DA2FE1A254CA2"; vout = 2840997408 }; value = 17445848412223914426; height = 118915440 }, { outpoint = { txid = "xF7CBBA21D83DB97344666081C6741A2AA3EF195DD53147822C629DF98B40FE3A"; vout = 3953357992 }; value = 8739665398422254929; height = 3378598018 }, { outpoint = { txid = "xD706D81F6BD23CB10726A014187038BCE35CB2F3ECCB7DD75F4647487E926B57"; vout = 2056624229 }; value = 1763343418669589207; height = 3388535713 }, { outpoint = { txid = "xF4197FF183421A910092C007EDB6472B7A3158CE1700CC21E6E714AF1108697F"; vout = 92794092 }; value = 4919859010227508177; height = 2337925836 } ]; tip_block_hash = "x0FC80915A4320DA282A98A18083753F3DE7592A2198D6B99C8F949A2EC8A4F52"; tip_height = 2903633966; next_page = ?"x17691617B8B442AFB32C31DF22DF57966FEA580488256723D7E15DA9ECEEEA00" }) - }; - public shared func bitcoin_send_transaction(_arg0 : T.BitcoinSendTransactionArgs) : async () { - () - }; - public shared func bitcoin_get_current_fee_percentiles(_arg0 : T.BitcoinGetCurrentFeePercentilesArgs) : async (T.BitcoinGetCurrentFeePercentilesResult) { - ([ 14445098301504250376, 14519010981886906783, 3800013330962312753, 6412741098828968161 ]) - }; - public shared func node_metrics_history(_arg0 : T.NodeMetricsHistoryArgs) : async (T.NodeMetricsHistoryResult) { - ([ { timestamp_nanos = 14445098301504250376; node_metrics = [ { node_id = principalOfBlob("x31EEC1BDFD5BBCE1B03FA00DA2FE1A254CA23FD9613D005FB6E22DF7BA41EBE7"); num_blocks_total = 2946348513676687635; num_block_failures_total = 628601621483015159 }, { node_id = principalOfBlob("x7344666081C6741A2AA3EF195DD53147822C629DF98B40FE3A93E721D185BD47"); num_blocks_total = 8739665398422254929; num_block_failures_total = 6996900549006677128 }, { node_id = principalOfBlob("xD706D81F6BD23CB10726A014187038BCE35CB2F3ECCB7DD75F4647487E926B57"); num_blocks_total = 10057912679290418714; num_block_failures_total = 1763343418669589207 }, { node_id = principalOfBlob("x32A886DE6E4B72F4197FF183421A910092C007EDB6472B7A3158CE1700CC21E6"); num_blocks_total = 16736904521429092369; num_block_failures_total = 692044588527733257 }, { node_id = principalOfBlob("xD1939D09B4D94630190C629CD14D0FC80915A4320DA282A98A18083753F3DE75"); num_blocks_total = 5377942242194975629; num_block_failures_total = 14536374534758435564 } ] }, { timestamp_nanos = 2699673602518336856; node_metrics = [ { node_id = principalOfBlob("xAFB32C31DF22DF57966FEA580488256723D7E15DA9ECEEEA0032F8BB554AD41C"); num_blocks_total = 14039119793643782529; num_block_failures_total = 3420742533394811059 }, { node_id = principalOfBlob("x9A5543731482481F165AAA1560662B8E9D514E23991BA4248FFA389E4C1E233D"); num_blocks_total = 9736605414087480391; num_block_failures_total = 14670472641987634058 }, { node_id = principalOfBlob("xFC639D6958FD1EA1E5B346359864D5BE44010FF463BBE3FC7A6969524896FE46"); num_blocks_total = 5874018963714161346; num_block_failures_total = 12468803627480752232 } ] }, { timestamp_nanos = 6060388434559489450; node_metrics = [ { node_id = principalOfBlob("x2E48D130F2D796F8C698FD6E1D95443E119353DE510A61BC14E1216A7498623D"); num_blocks_total = 14370068839309583932; num_block_failures_total = 10541212000563527943 }, { node_id = principalOfBlob("x9073DCDDD8B951CDB2FC3A3922F1FD0E74B0990E0078D2B236027D6B7FC5C5F8"); num_blocks_total = 4965205962592385158; num_block_failures_total = 11603411761932611421 }, { node_id = principalOfBlob("xBFA3479ED1F3DDB8E186099D10294826ED8361D159D92065148671911683101A"); num_blocks_total = 14947274454573152686; num_block_failures_total = 7716925642222139723 }, { node_id = principalOfBlob("x773EAA160280F8E6C4C477AF447EC1D59F4DE45FA855620A308ACE5E7985E23E"); num_blocks_total = 8782559658733379294; num_block_failures_total = 4291121491176080988 }, { node_id = principalOfBlob("x3A6C38A387F9DD652E440339C1E0698E3FF7D098E5ADF0DE507011E9EC36CC81"); num_blocks_total = 11022318376113958984; num_block_failures_total = 17477312328600877330 } ] }, { timestamp_nanos = 16930824079303685760; node_metrics = [ { node_id = principalOfBlob("xDA90DE1A63AF6E2336D10DD0AA6B73AD0792645EEBDDE279F464613D0D3FEEFD"); num_blocks_total = 13738085029865269207; num_block_failures_total = 17402500047223268475 }, { node_id = principalOfBlob("x7530A112A44E62E38FBB862EA149FDD66F9AA60B04B09AFBD59DEDE608B1C0A7"); num_blocks_total = 8262129053821897548; num_block_failures_total = 7283261748982717338 }, { node_id = principalOfBlob("xEE92E855F1BEE87F3FE35C84FDD06850DAC8F040ACD17D576AEF2F3A2A75B35E"); num_blocks_total = 8934560208994098493; num_block_failures_total = 11869455582429884453 } ] } ]) - }; - public shared func provisional_create_canister_with_cycles(_arg0 : T.ProvisionalCreateCanisterWithCyclesArgs) : async (T.ProvisionalCreateCanisterWithCyclesResult) { - ({ canister_id = principalOfBlob("x869AF7A6140D470862C22E5F4C779F515D2190E37D31EEC1BDFD5BBCE1B03FA0") }) - }; - public shared func provisional_top_up_canister(_arg0 : T.ProvisionalTopUpCanisterArgs) : async () { - () - }; -} diff --git a/ic/ic/agent_test.go b/ic/ic/agent_test.go deleted file mode 100755 index c7dbf66..0000000 --- a/ic/ic/agent_test.go +++ /dev/null @@ -1,860 +0,0 @@ -// Do NOT edit this file. It was automatically generated by https://github.com/aviate-labs/agent-go. -package ic_test - -import ( - "github.com/aviate-labs/agent-go" - "github.com/aviate-labs/agent-go/candid/idl" - "github.com/aviate-labs/agent-go/mock" - "github.com/aviate-labs/agent-go/principal" - "net/http/httptest" - "net/url" - "testing" - - "github.com/aviate-labs/agent-go/ic/ic" -) - -// Test_BitcoinGetBalance tests the "bitcoin_get_balance" method on the "ic" canister. -func Test_BitcoinGetBalance(t *testing.T) { - a, err := newAgent([]mock.Method{ - { - Name: "bitcoin_get_balance", - Arguments: []any{new(ic.BitcoinGetBalanceArgs)}, - Handler: func(request mock.Request) ([]any, error) { - return []any{*new(ic.Satoshi)}, nil - }, - }, - }) - if err != nil { - t.Fatal(err) - } - - var a0 = ic.BitcoinGetBalanceArgs{ - *new(string), - ic.BitcoinNetwork{ - Mainnet: new(idl.Null), - }, - *new(*uint32), - } - if _, err := a.BitcoinGetBalance(a0); err != nil { - t.Fatal(err) - } - -} - -// Test_BitcoinGetBalanceQuery tests the "bitcoin_get_balance_query" method on the "ic" canister. -func Test_BitcoinGetBalanceQuery(t *testing.T) { - a, err := newAgent([]mock.Method{ - { - Name: "bitcoin_get_balance_query", - Arguments: []any{new(ic.BitcoinGetBalanceQueryArgs)}, - Handler: func(request mock.Request) ([]any, error) { - return []any{*new(ic.Satoshi)}, nil - }, - }, - }) - if err != nil { - t.Fatal(err) - } - - var a0 = ic.BitcoinGetBalanceQueryArgs{ - *new(string), - ic.BitcoinNetwork{ - Mainnet: new(idl.Null), - }, - *new(*uint32), - } - if _, err := a.BitcoinGetBalanceQuery(a0); err != nil { - t.Fatal(err) - } - -} - -// Test_BitcoinGetCurrentFeePercentiles tests the "bitcoin_get_current_fee_percentiles" method on the "ic" canister. -func Test_BitcoinGetCurrentFeePercentiles(t *testing.T) { - a, err := newAgent([]mock.Method{ - { - Name: "bitcoin_get_current_fee_percentiles", - Arguments: []any{new(ic.BitcoinGetCurrentFeePercentilesArgs)}, - Handler: func(request mock.Request) ([]any, error) { - return []any{*new([]ic.MillisatoshiPerByte)}, nil - }, - }, - }) - if err != nil { - t.Fatal(err) - } - - var a0 = ic.BitcoinGetCurrentFeePercentilesArgs{ - ic.BitcoinNetwork{ - Mainnet: new(idl.Null), - }, - } - if _, err := a.BitcoinGetCurrentFeePercentiles(a0); err != nil { - t.Fatal(err) - } - -} - -// Test_BitcoinGetUtxos tests the "bitcoin_get_utxos" method on the "ic" canister. -func Test_BitcoinGetUtxos(t *testing.T) { - a, err := newAgent([]mock.Method{ - { - Name: "bitcoin_get_utxos", - Arguments: []any{new(ic.BitcoinGetUtxosArgs)}, - Handler: func(request mock.Request) ([]any, error) { - return []any{ic.BitcoinGetUtxosResult{ - []ic.Utxo{{ - ic.Outpoint{ - *new([]byte), - *new(uint32), - }, - *new(uint64), - *new(uint32), - }}, - *new([]byte), - *new(uint32), - *new(*[]byte), - }}, nil - }, - }, - }) - if err != nil { - t.Fatal(err) - } - - var a0 = ic.BitcoinGetUtxosArgs{ - *new(string), - ic.BitcoinNetwork{ - Mainnet: new(idl.Null), - }, - *new(*struct { - MinConfirmations *uint32 `ic:"min_confirmations,variant"` - Page *[]byte `ic:"page,variant"` - }), - } - if _, err := a.BitcoinGetUtxos(a0); err != nil { - t.Fatal(err) - } - -} - -// Test_BitcoinGetUtxosQuery tests the "bitcoin_get_utxos_query" method on the "ic" canister. -func Test_BitcoinGetUtxosQuery(t *testing.T) { - a, err := newAgent([]mock.Method{ - { - Name: "bitcoin_get_utxos_query", - Arguments: []any{new(ic.BitcoinGetUtxosQueryArgs)}, - Handler: func(request mock.Request) ([]any, error) { - return []any{ic.BitcoinGetUtxosQueryResult{ - []ic.Utxo{{ - ic.Outpoint{ - *new([]byte), - *new(uint32), - }, - *new(uint64), - *new(uint32), - }}, - *new([]byte), - *new(uint32), - *new(*[]byte), - }}, nil - }, - }, - }) - if err != nil { - t.Fatal(err) - } - - var a0 = ic.BitcoinGetUtxosQueryArgs{ - *new(string), - ic.BitcoinNetwork{ - Mainnet: new(idl.Null), - }, - *new(*struct { - MinConfirmations *uint32 `ic:"min_confirmations,variant"` - Page *[]byte `ic:"page,variant"` - }), - } - if _, err := a.BitcoinGetUtxosQuery(a0); err != nil { - t.Fatal(err) - } - -} - -// Test_BitcoinSendTransaction tests the "bitcoin_send_transaction" method on the "ic" canister. -func Test_BitcoinSendTransaction(t *testing.T) { - a, err := newAgent([]mock.Method{ - { - Name: "bitcoin_send_transaction", - Arguments: []any{new(ic.BitcoinSendTransactionArgs)}, - Handler: func(request mock.Request) ([]any, error) { - return []any{}, nil - }, - }, - }) - if err != nil { - t.Fatal(err) - } - - var a0 = ic.BitcoinSendTransactionArgs{ - *new([]byte), - ic.BitcoinNetwork{ - Mainnet: new(idl.Null), - }, - } - if err := a.BitcoinSendTransaction(a0); err != nil { - t.Fatal(err) - } - -} - -// Test_CanisterInfo tests the "canister_info" method on the "ic" canister. -func Test_CanisterInfo(t *testing.T) { - a, err := newAgent([]mock.Method{ - { - Name: "canister_info", - Arguments: []any{new(ic.CanisterInfoArgs)}, - Handler: func(request mock.Request) ([]any, error) { - return []any{ic.CanisterInfoResult{ - *new(uint64), - []ic.Change{{ - *new(uint64), - *new(uint64), - ic.ChangeOrigin{ - FromUser: idl.Ptr(struct { - UserId principal.Principal `ic:"user_id" json:"user_id"` - }{ - *new(principal.Principal), - }), - }, - ic.ChangeDetails{ - Creation: idl.Ptr(struct { - Controllers []principal.Principal `ic:"controllers" json:"controllers"` - }{ - []principal.Principal{*new(principal.Principal)}, - }), - }, - }}, - *new(*[]byte), - []principal.Principal{*new(principal.Principal)}, - }}, nil - }, - }, - }) - if err != nil { - t.Fatal(err) - } - - var a0 = ic.CanisterInfoArgs{ - *new(principal.Principal), - *new(*uint64), - } - if _, err := a.CanisterInfo(a0); err != nil { - t.Fatal(err) - } - -} - -// Test_CanisterStatus tests the "canister_status" method on the "ic" canister. -func Test_CanisterStatus(t *testing.T) { - a, err := newAgent([]mock.Method{ - { - Name: "canister_status", - Arguments: []any{new(ic.CanisterStatusArgs)}, - Handler: func(request mock.Request) ([]any, error) { - return []any{ic.CanisterStatusResult{ - struct { - Running *idl.Null `ic:"running,variant"` - Stopping *idl.Null `ic:"stopping,variant"` - Stopped *idl.Null `ic:"stopped,variant"` - }{ - Running: new(idl.Null), - }, - ic.DefiniteCanisterSettings{ - []principal.Principal{*new(principal.Principal)}, - idl.NewNat(uint(0)), - idl.NewNat(uint(0)), - idl.NewNat(uint(0)), - idl.NewNat(uint(0)), - }, - *new(*[]byte), - idl.NewNat(uint(0)), - idl.NewNat(uint(0)), - idl.NewNat(uint(0)), - idl.NewNat(uint(0)), - }}, nil - }, - }, - }) - if err != nil { - t.Fatal(err) - } - - var a0 = ic.CanisterStatusArgs{ - *new(principal.Principal), - } - if _, err := a.CanisterStatus(a0); err != nil { - t.Fatal(err) - } - -} - -// Test_ClearChunkStore tests the "clear_chunk_store" method on the "ic" canister. -func Test_ClearChunkStore(t *testing.T) { - a, err := newAgent([]mock.Method{ - { - Name: "clear_chunk_store", - Arguments: []any{new(ic.ClearChunkStoreArgs)}, - Handler: func(request mock.Request) ([]any, error) { - return []any{}, nil - }, - }, - }) - if err != nil { - t.Fatal(err) - } - - var a0 = ic.ClearChunkStoreArgs{ - *new(principal.Principal), - } - if err := a.ClearChunkStore(a0); err != nil { - t.Fatal(err) - } - -} - -// Test_CreateCanister tests the "create_canister" method on the "ic" canister. -func Test_CreateCanister(t *testing.T) { - a, err := newAgent([]mock.Method{ - { - Name: "create_canister", - Arguments: []any{new(ic.CreateCanisterArgs)}, - Handler: func(request mock.Request) ([]any, error) { - return []any{ic.CreateCanisterResult{ - *new(principal.Principal), - }}, nil - }, - }, - }) - if err != nil { - t.Fatal(err) - } - - var a0 = ic.CreateCanisterArgs{ - *new(*ic.CanisterSettings), - *new(*uint64), - } - if _, err := a.CreateCanister(a0); err != nil { - t.Fatal(err) - } - -} - -// Test_DeleteCanister tests the "delete_canister" method on the "ic" canister. -func Test_DeleteCanister(t *testing.T) { - a, err := newAgent([]mock.Method{ - { - Name: "delete_canister", - Arguments: []any{new(ic.DeleteCanisterArgs)}, - Handler: func(request mock.Request) ([]any, error) { - return []any{}, nil - }, - }, - }) - if err != nil { - t.Fatal(err) - } - - var a0 = ic.DeleteCanisterArgs{ - *new(principal.Principal), - } - if err := a.DeleteCanister(a0); err != nil { - t.Fatal(err) - } - -} - -// Test_DepositCycles tests the "deposit_cycles" method on the "ic" canister. -func Test_DepositCycles(t *testing.T) { - a, err := newAgent([]mock.Method{ - { - Name: "deposit_cycles", - Arguments: []any{new(ic.DepositCyclesArgs)}, - Handler: func(request mock.Request) ([]any, error) { - return []any{}, nil - }, - }, - }) - if err != nil { - t.Fatal(err) - } - - var a0 = ic.DepositCyclesArgs{ - *new(principal.Principal), - } - if err := a.DepositCycles(a0); err != nil { - t.Fatal(err) - } - -} - -// Test_EcdsaPublicKey tests the "ecdsa_public_key" method on the "ic" canister. -func Test_EcdsaPublicKey(t *testing.T) { - a, err := newAgent([]mock.Method{ - { - Name: "ecdsa_public_key", - Arguments: []any{new(ic.EcdsaPublicKeyArgs)}, - Handler: func(request mock.Request) ([]any, error) { - return []any{ic.EcdsaPublicKeyResult{ - *new([]byte), - *new([]byte), - }}, nil - }, - }, - }) - if err != nil { - t.Fatal(err) - } - - var a0 = ic.EcdsaPublicKeyArgs{ - *new(*ic.CanisterId), - [][]byte{*new([]byte)}, - struct { - Curve ic.EcdsaCurve `ic:"curve" json:"curve"` - Name string `ic:"name" json:"name"` - }{ - ic.EcdsaCurve{ - Secp256k1: new(idl.Null), - }, - *new(string), - }, - } - if _, err := a.EcdsaPublicKey(a0); err != nil { - t.Fatal(err) - } - -} - -// Test_HttpRequest tests the "http_request" method on the "ic" canister. -func Test_HttpRequest(t *testing.T) { - a, err := newAgent([]mock.Method{ - { - Name: "http_request", - Arguments: []any{new(ic.HttpRequestArgs)}, - Handler: func(request mock.Request) ([]any, error) { - return []any{ic.HttpRequestResult{ - idl.NewNat(uint(0)), - []ic.HttpHeader{{ - *new(string), - *new(string), - }}, - *new([]byte), - }}, nil - }, - }, - }) - if err != nil { - t.Fatal(err) - } - - var a0 = ic.HttpRequestArgs{ - *new(string), - *new(*uint64), - struct { - Get *idl.Null `ic:"get,variant"` - Head *idl.Null `ic:"head,variant"` - Post *idl.Null `ic:"post,variant"` - }{ - Get: new(idl.Null), - }, - []ic.HttpHeader{{ - *new(string), - *new(string), - }}, - *new(*[]byte), - *new(*struct { - Function struct { /* NOT SUPPORTED */ - } `ic:"function" json:"function"` - Context []byte `ic:"context" json:"context"` - }), - } - if _, err := a.HttpRequest(a0); err != nil { - t.Fatal(err) - } - -} - -// Test_InstallChunkedCode tests the "install_chunked_code" method on the "ic" canister. -func Test_InstallChunkedCode(t *testing.T) { - a, err := newAgent([]mock.Method{ - { - Name: "install_chunked_code", - Arguments: []any{new(ic.InstallChunkedCodeArgs)}, - Handler: func(request mock.Request) ([]any, error) { - return []any{}, nil - }, - }, - }) - if err != nil { - t.Fatal(err) - } - - var a0 = ic.InstallChunkedCodeArgs{ - ic.CanisterInstallMode{ - Install: new(idl.Null), - }, - *new(principal.Principal), - *new(*ic.CanisterId), - []ic.ChunkHash{{ - *new([]byte), - }}, - *new([]byte), - *new([]byte), - *new(*uint64), - } - if err := a.InstallChunkedCode(a0); err != nil { - t.Fatal(err) - } - -} - -// Test_InstallCode tests the "install_code" method on the "ic" canister. -func Test_InstallCode(t *testing.T) { - a, err := newAgent([]mock.Method{ - { - Name: "install_code", - Arguments: []any{new(ic.InstallCodeArgs)}, - Handler: func(request mock.Request) ([]any, error) { - return []any{}, nil - }, - }, - }) - if err != nil { - t.Fatal(err) - } - - var a0 = ic.InstallCodeArgs{ - ic.CanisterInstallMode{ - Install: new(idl.Null), - }, - *new(principal.Principal), - *new([]byte), - *new([]byte), - *new(*uint64), - } - if err := a.InstallCode(a0); err != nil { - t.Fatal(err) - } - -} - -// Test_NodeMetricsHistory tests the "node_metrics_history" method on the "ic" canister. -func Test_NodeMetricsHistory(t *testing.T) { - a, err := newAgent([]mock.Method{ - { - Name: "node_metrics_history", - Arguments: []any{new(ic.NodeMetricsHistoryArgs)}, - Handler: func(request mock.Request) ([]any, error) { - return []any{*new([]struct { - TimestampNanos uint64 `ic:"timestamp_nanos" json:"timestamp_nanos"` - NodeMetrics []ic.NodeMetrics `ic:"node_metrics" json:"node_metrics"` - })}, nil - }, - }, - }) - if err != nil { - t.Fatal(err) - } - - var a0 = ic.NodeMetricsHistoryArgs{ - *new(principal.Principal), - *new(uint64), - } - if _, err := a.NodeMetricsHistory(a0); err != nil { - t.Fatal(err) - } - -} - -// Test_ProvisionalCreateCanisterWithCycles tests the "provisional_create_canister_with_cycles" method on the "ic" canister. -func Test_ProvisionalCreateCanisterWithCycles(t *testing.T) { - a, err := newAgent([]mock.Method{ - { - Name: "provisional_create_canister_with_cycles", - Arguments: []any{new(ic.ProvisionalCreateCanisterWithCyclesArgs)}, - Handler: func(request mock.Request) ([]any, error) { - return []any{ic.ProvisionalCreateCanisterWithCyclesResult{ - *new(principal.Principal), - }}, nil - }, - }, - }) - if err != nil { - t.Fatal(err) - } - - var a0 = ic.ProvisionalCreateCanisterWithCyclesArgs{ - *new(*idl.Nat), - *new(*ic.CanisterSettings), - *new(*ic.CanisterId), - *new(*uint64), - } - if _, err := a.ProvisionalCreateCanisterWithCycles(a0); err != nil { - t.Fatal(err) - } - -} - -// Test_ProvisionalTopUpCanister tests the "provisional_top_up_canister" method on the "ic" canister. -func Test_ProvisionalTopUpCanister(t *testing.T) { - a, err := newAgent([]mock.Method{ - { - Name: "provisional_top_up_canister", - Arguments: []any{new(ic.ProvisionalTopUpCanisterArgs)}, - Handler: func(request mock.Request) ([]any, error) { - return []any{}, nil - }, - }, - }) - if err != nil { - t.Fatal(err) - } - - var a0 = ic.ProvisionalTopUpCanisterArgs{ - *new(principal.Principal), - idl.NewNat(uint(0)), - } - if err := a.ProvisionalTopUpCanister(a0); err != nil { - t.Fatal(err) - } - -} - -// Test_RawRand tests the "raw_rand" method on the "ic" canister. -func Test_RawRand(t *testing.T) { - a, err := newAgent([]mock.Method{ - { - Name: "raw_rand", - Arguments: []any{}, - Handler: func(request mock.Request) ([]any, error) { - return []any{*new([]byte)}, nil - }, - }, - }) - if err != nil { - t.Fatal(err) - } - - if _, err := a.RawRand(); err != nil { - t.Fatal(err) - } - -} - -// Test_SignWithEcdsa tests the "sign_with_ecdsa" method on the "ic" canister. -func Test_SignWithEcdsa(t *testing.T) { - a, err := newAgent([]mock.Method{ - { - Name: "sign_with_ecdsa", - Arguments: []any{new(ic.SignWithEcdsaArgs)}, - Handler: func(request mock.Request) ([]any, error) { - return []any{ic.SignWithEcdsaResult{ - *new([]byte), - }}, nil - }, - }, - }) - if err != nil { - t.Fatal(err) - } - - var a0 = ic.SignWithEcdsaArgs{ - *new([]byte), - [][]byte{*new([]byte)}, - struct { - Curve ic.EcdsaCurve `ic:"curve" json:"curve"` - Name string `ic:"name" json:"name"` - }{ - ic.EcdsaCurve{ - Secp256k1: new(idl.Null), - }, - *new(string), - }, - } - if _, err := a.SignWithEcdsa(a0); err != nil { - t.Fatal(err) - } - -} - -// Test_StartCanister tests the "start_canister" method on the "ic" canister. -func Test_StartCanister(t *testing.T) { - a, err := newAgent([]mock.Method{ - { - Name: "start_canister", - Arguments: []any{new(ic.StartCanisterArgs)}, - Handler: func(request mock.Request) ([]any, error) { - return []any{}, nil - }, - }, - }) - if err != nil { - t.Fatal(err) - } - - var a0 = ic.StartCanisterArgs{ - *new(principal.Principal), - } - if err := a.StartCanister(a0); err != nil { - t.Fatal(err) - } - -} - -// Test_StopCanister tests the "stop_canister" method on the "ic" canister. -func Test_StopCanister(t *testing.T) { - a, err := newAgent([]mock.Method{ - { - Name: "stop_canister", - Arguments: []any{new(ic.StopCanisterArgs)}, - Handler: func(request mock.Request) ([]any, error) { - return []any{}, nil - }, - }, - }) - if err != nil { - t.Fatal(err) - } - - var a0 = ic.StopCanisterArgs{ - *new(principal.Principal), - } - if err := a.StopCanister(a0); err != nil { - t.Fatal(err) - } - -} - -// Test_StoredChunks tests the "stored_chunks" method on the "ic" canister. -func Test_StoredChunks(t *testing.T) { - a, err := newAgent([]mock.Method{ - { - Name: "stored_chunks", - Arguments: []any{new(ic.StoredChunksArgs)}, - Handler: func(request mock.Request) ([]any, error) { - return []any{*new([]ic.ChunkHash)}, nil - }, - }, - }) - if err != nil { - t.Fatal(err) - } - - var a0 = ic.StoredChunksArgs{ - *new(principal.Principal), - } - if _, err := a.StoredChunks(a0); err != nil { - t.Fatal(err) - } - -} - -// Test_UninstallCode tests the "uninstall_code" method on the "ic" canister. -func Test_UninstallCode(t *testing.T) { - a, err := newAgent([]mock.Method{ - { - Name: "uninstall_code", - Arguments: []any{new(ic.UninstallCodeArgs)}, - Handler: func(request mock.Request) ([]any, error) { - return []any{}, nil - }, - }, - }) - if err != nil { - t.Fatal(err) - } - - var a0 = ic.UninstallCodeArgs{ - *new(principal.Principal), - *new(*uint64), - } - if err := a.UninstallCode(a0); err != nil { - t.Fatal(err) - } - -} - -// Test_UpdateSettings tests the "update_settings" method on the "ic" canister. -func Test_UpdateSettings(t *testing.T) { - a, err := newAgent([]mock.Method{ - { - Name: "update_settings", - Arguments: []any{new(ic.UpdateSettingsArgs)}, - Handler: func(request mock.Request) ([]any, error) { - return []any{}, nil - }, - }, - }) - if err != nil { - t.Fatal(err) - } - - var a0 = ic.UpdateSettingsArgs{ - *new(principal.Principal), - ic.CanisterSettings{ - *new(*[]principal.Principal), - *new(*idl.Nat), - *new(*idl.Nat), - *new(*idl.Nat), - *new(*idl.Nat), - }, - *new(*uint64), - } - if err := a.UpdateSettings(a0); err != nil { - t.Fatal(err) - } - -} - -// Test_UploadChunk tests the "upload_chunk" method on the "ic" canister. -func Test_UploadChunk(t *testing.T) { - a, err := newAgent([]mock.Method{ - { - Name: "upload_chunk", - Arguments: []any{new(ic.UploadChunkArgs)}, - Handler: func(request mock.Request) ([]any, error) { - return []any{*new(ic.ChunkHash)}, nil - }, - }, - }) - if err != nil { - t.Fatal(err) - } - - var a0 = ic.UploadChunkArgs{ - *new(principal.Principal), - *new([]byte), - } - if _, err := a.UploadChunk(a0); err != nil { - t.Fatal(err) - } - -} - -// newAgent creates a new agent with the given (mock) methods. -// Runs a mock replica in the background. -func newAgent(methods []mock.Method) (*ic.Agent, error) { - replica := mock.NewReplica() - canisterId := principal.Principal{Raw: []byte("ic")} - replica.AddCanister(canisterId, methods) - s := httptest.NewServer(replica) - u, _ := url.Parse(s.URL) - a, err := ic.NewAgent(canisterId, agent.Config{ - ClientConfig: &agent.ClientConfig{Host: u}, - FetchRootKey: true, - }) - if err != nil { - return nil, err - } - return a, nil -} diff --git a/ic/ic/types.mo b/ic/ic/types.mo deleted file mode 100755 index 26e717b..0000000 --- a/ic/ic/types.mo +++ /dev/null @@ -1,64 +0,0 @@ -// Do NOT edit this file. It was automatically generated by https://github.com/aviate-labs/agent-go. -module T { - public type CanisterId = Principal; - public type WasmModule = Blob; - public type CanisterSettings = { controllers : ?[Principal]; compute_allocation : ?Nat; memory_allocation : ?Nat; freezing_threshold : ?Nat; reserved_cycles_limit : ?Nat }; - public type DefiniteCanisterSettings = { controllers : [Principal]; compute_allocation : Nat; memory_allocation : Nat; freezing_threshold : Nat; reserved_cycles_limit : Nat }; - public type ChangeOrigin = { #from_user : { user_id : Principal }; #from_canister : { canister_id : Principal; canister_version : ?Nat64 } }; - public type ChangeDetails = { #creation : { controllers : [Principal] }; #code_uninstall; #code_deployment : { mode : { #install; #reinstall; #upgrade }; module_hash : Blob }; #controllers_change : { controllers : [Principal] } }; - public type Change = { timestamp_nanos : Nat64; canister_version : Nat64; origin : T.ChangeOrigin; details : T.ChangeDetails }; - public type ChunkHash = { hash : Blob }; - public type HttpHeader = { name : Text; value : Text }; - public type HttpRequestResult = { status : Nat; headers : [T.HttpHeader]; body : Blob }; - public type EcdsaCurve = { #secp256k1 }; - public type Satoshi = Nat64; - public type BitcoinNetwork = { #mainnet; #testnet }; - public type BitcoinAddress = Text; - public type BlockHash = Blob; - public type Outpoint = { txid : Blob; vout : Nat32 }; - public type Utxo = { outpoint : T.Outpoint; value : T.Satoshi; height : Nat32 }; - public type BitcoinGetUtxosArgs = { address : T.BitcoinAddress; network : T.BitcoinNetwork; filter : ?{ #min_confirmations : Nat32; #page : Blob } }; - public type BitcoinGetUtxosQueryArgs = { address : T.BitcoinAddress; network : T.BitcoinNetwork; filter : ?{ #min_confirmations : Nat32; #page : Blob } }; - public type BitcoinGetCurrentFeePercentilesArgs = { network : T.BitcoinNetwork }; - public type BitcoinGetUtxosResult = { utxos : [T.Utxo]; tip_block_hash : T.BlockHash; tip_height : Nat32; next_page : ?Blob }; - public type BitcoinGetUtxosQueryResult = { utxos : [T.Utxo]; tip_block_hash : T.BlockHash; tip_height : Nat32; next_page : ?Blob }; - public type BitcoinGetBalanceArgs = { address : T.BitcoinAddress; network : T.BitcoinNetwork; min_confirmations : ?Nat32 }; - public type BitcoinGetBalanceQueryArgs = { address : T.BitcoinAddress; network : T.BitcoinNetwork; min_confirmations : ?Nat32 }; - public type BitcoinSendTransactionArgs = { transaction : Blob; network : T.BitcoinNetwork }; - public type MillisatoshiPerByte = Nat64; - public type NodeMetrics = { node_id : Principal; num_blocks_total : Nat64; num_block_failures_total : Nat64 }; - public type CreateCanisterArgs = { settings : ?T.CanisterSettings; sender_canister_version : ?Nat64 }; - public type CreateCanisterResult = { canister_id : T.CanisterId }; - public type UpdateSettingsArgs = { canister_id : Principal; settings : T.CanisterSettings; sender_canister_version : ?Nat64 }; - public type UploadChunkArgs = { canister_id : Principal; chunk : Blob }; - public type ClearChunkStoreArgs = { canister_id : T.CanisterId }; - public type StoredChunksArgs = { canister_id : T.CanisterId }; - public type CanisterInstallMode = { #install; #reinstall; #upgrade : ?{ skip_pre_upgrade : ?Bool } }; - public type InstallCodeArgs = { mode : T.CanisterInstallMode; canister_id : T.CanisterId; wasm_module : T.WasmModule; arg : Blob; sender_canister_version : ?Nat64 }; - public type InstallChunkedCodeArgs = { mode : T.CanisterInstallMode; target_canister : T.CanisterId; store_canister : ?T.CanisterId; chunk_hashes_list : [T.ChunkHash]; wasm_module_hash : Blob; arg : Blob; sender_canister_version : ?Nat64 }; - public type UninstallCodeArgs = { canister_id : T.CanisterId; sender_canister_version : ?Nat64 }; - public type StartCanisterArgs = { canister_id : T.CanisterId }; - public type StopCanisterArgs = { canister_id : T.CanisterId }; - public type CanisterStatusArgs = { canister_id : T.CanisterId }; - public type CanisterStatusResult = { status : { #running; #stopping; #stopped }; settings : T.DefiniteCanisterSettings; module_hash : ?Blob; memory_size : Nat; cycles : Nat; reserved_cycles : Nat; idle_cycles_burned_per_day : Nat }; - public type CanisterInfoArgs = { canister_id : T.CanisterId; num_requested_changes : ?Nat64 }; - public type CanisterInfoResult = { total_num_changes : Nat64; recent_changes : [T.Change]; module_hash : ?Blob; controllers : [Principal] }; - public type DeleteCanisterArgs = { canister_id : T.CanisterId }; - public type DepositCyclesArgs = { canister_id : T.CanisterId }; - public type HttpRequestArgs = { url : Text; max_response_bytes : ?Nat64; method : { #get; #head; #post }; headers : [T.HttpHeader]; body : ?Blob; transform : ?{ function : { /* func */ }; context : Blob } }; - public type EcdsaPublicKeyArgs = { canister_id : ?T.CanisterId; derivation_path : [Blob]; key_id : { curve : T.EcdsaCurve; name : Text } }; - public type EcdsaPublicKeyResult = { public_key : Blob; chain_code : Blob }; - public type SignWithEcdsaArgs = { message_hash : Blob; derivation_path : [Blob]; key_id : { curve : T.EcdsaCurve; name : Text } }; - public type SignWithEcdsaResult = { signature : Blob }; - public type NodeMetricsHistoryArgs = { subnet_id : Principal; start_at_timestamp_nanos : Nat64 }; - public type NodeMetricsHistoryResult = [{ timestamp_nanos : Nat64; node_metrics : [T.NodeMetrics] }]; - public type ProvisionalCreateCanisterWithCyclesArgs = { amount : ?Nat; settings : ?T.CanisterSettings; specified_id : ?T.CanisterId; sender_canister_version : ?Nat64 }; - public type ProvisionalCreateCanisterWithCyclesResult = { canister_id : T.CanisterId }; - public type ProvisionalTopUpCanisterArgs = { canister_id : T.CanisterId; amount : Nat }; - public type RawRandResult = Blob; - public type StoredChunksResult = [T.ChunkHash]; - public type UploadChunkResult = T.ChunkHash; - public type BitcoinGetBalanceResult = T.Satoshi; - public type BitcoinGetBalanceQueryResult = T.Satoshi; - public type BitcoinGetCurrentFeePercentilesResult = [T.MillisatoshiPerByte]; -}; diff --git a/ic/testdata/gen.go b/ic/testdata/gen.go index bf86121..d09be00 100644 --- a/ic/testdata/gen.go +++ b/ic/testdata/gen.go @@ -31,10 +31,12 @@ func checkLatest() error { filepath: "ic/testdata/did/cmc.did", remote: "https://raw.githubusercontent.com/dfinity/ic/master/rs/nns/cmc/cmc.did", }, + /* Needs custom implementation. { filepath: "ic/testdata/did/ic.did", remote: "https://raw.githubusercontent.com/dfinity/interface-spec/master/spec/_attachments/ic.did", }, + */ { filepath: "ic/testdata/did/icparchive.did", remote: "https://raw.githubusercontent.com/dfinity/ic/master/rs/rosetta-api/icp_ledger/ledger_archive.did", diff --git a/logger.go b/logger.go new file mode 100644 index 0000000..dc339c0 --- /dev/null +++ b/logger.go @@ -0,0 +1,9 @@ +package agent + +type Logger interface { + Printf(format string, v ...interface{}) +} + +type defaultLogger struct{} + +func (l defaultLogger) Printf(format string, v ...interface{}) {} diff --git a/ic/ic/agent.go b/mgmt/agent.go similarity index 87% rename from ic/ic/agent.go rename to mgmt/agent.go index 1882fa9..d697fc8 100755 --- a/ic/ic/agent.go +++ b/mgmt/agent.go @@ -1,8 +1,7 @@ -// Package ic provides a client for the "ic" canister. -// Do NOT edit this file. It was automatically generated by https://github.com/aviate-labs/agent-go. -package ic +package mgmt import ( + "fmt" "github.com/aviate-labs/agent-go" "github.com/aviate-labs/agent-go/candid/idl" "github.com/aviate-labs/agent-go/principal" @@ -15,29 +14,20 @@ type Agent struct { } // NewAgent creates a new agent for the "ic" canister. -func NewAgent(canisterId principal.Principal, config agent.Config) (*Agent, error) { +func NewAgent(config agent.Config) (*Agent, error) { a, err := agent.New(config) if err != nil { return nil, err } return &Agent{ a: a, - canisterId: canisterId, + canisterId: principal.Principal{}, // aaaaa-aa }, nil } // BitcoinGetBalance calls the "bitcoin_get_balance" method on the "ic" canister. -func (a Agent) BitcoinGetBalance(arg0 BitcoinGetBalanceArgs) (*BitcoinGetBalanceResult, error) { - var r0 BitcoinGetBalanceResult - if err := a.a.Call( - a.canisterId, - "bitcoin_get_balance", - []any{arg0}, - []any{&r0}, - ); err != nil { - return nil, err - } - return &r0, nil +func (a Agent) BitcoinGetBalance(_ BitcoinGetBalanceArgs) (*BitcoinGetBalanceResult, error) { + return nil, fmt.Errorf("bitcoin_get_balance is not accepted as an ingress message") } // BitcoinGetBalanceQuery calls the "bitcoin_get_balance_query" method on the "ic" canister. @@ -55,31 +45,13 @@ func (a Agent) BitcoinGetBalanceQuery(arg0 BitcoinGetBalanceQueryArgs) (*Bitcoin } // BitcoinGetCurrentFeePercentiles calls the "bitcoin_get_current_fee_percentiles" method on the "ic" canister. -func (a Agent) BitcoinGetCurrentFeePercentiles(arg0 BitcoinGetCurrentFeePercentilesArgs) (*BitcoinGetCurrentFeePercentilesResult, error) { - var r0 BitcoinGetCurrentFeePercentilesResult - if err := a.a.Call( - a.canisterId, - "bitcoin_get_current_fee_percentiles", - []any{arg0}, - []any{&r0}, - ); err != nil { - return nil, err - } - return &r0, nil +func (a Agent) BitcoinGetCurrentFeePercentiles(_ BitcoinGetCurrentFeePercentilesArgs) (*BitcoinGetCurrentFeePercentilesResult, error) { + return nil, fmt.Errorf("bitcoin_get_current_fee_percentiles is not accepted as an ingress message") } // BitcoinGetUtxos calls the "bitcoin_get_utxos" method on the "ic" canister. -func (a Agent) BitcoinGetUtxos(arg0 BitcoinGetUtxosArgs) (*BitcoinGetUtxosResult, error) { - var r0 BitcoinGetUtxosResult - if err := a.a.Call( - a.canisterId, - "bitcoin_get_utxos", - []any{arg0}, - []any{&r0}, - ); err != nil { - return nil, err - } - return &r0, nil +func (a Agent) BitcoinGetUtxos(_ BitcoinGetUtxosArgs) (*BitcoinGetUtxosResult, error) { + return nil, fmt.Errorf("bitcoin_get_utxos is not accepted as an ingress message") } // BitcoinGetUtxosQuery calls the "bitcoin_get_utxos_query" method on the "ic" canister. @@ -97,16 +69,8 @@ func (a Agent) BitcoinGetUtxosQuery(arg0 BitcoinGetUtxosQueryArgs) (*BitcoinGetU } // BitcoinSendTransaction calls the "bitcoin_send_transaction" method on the "ic" canister. -func (a Agent) BitcoinSendTransaction(arg0 BitcoinSendTransactionArgs) error { - if err := a.a.Call( - a.canisterId, - "bitcoin_send_transaction", - []any{arg0}, - []any{}, - ); err != nil { - return err - } - return nil +func (a Agent) BitcoinSendTransaction(_ BitcoinSendTransactionArgs) error { + return fmt.Errorf("bitcoin_send_transaction is not accepted as an ingress message") } // CanisterInfo calls the "canister_info" method on the "ic" canister. @@ -127,9 +91,9 @@ func (a Agent) CanisterInfo(arg0 CanisterInfoArgs) (*CanisterInfoResult, error) func (a Agent) CanisterStatus(arg0 CanisterStatusArgs) (*CanisterStatusResult, error) { var r0 CanisterStatusResult if err := a.a.Call( - a.canisterId, + arg0.CanisterId, "canister_status", - []any{arg0}, + []any{}, []any{&r0}, ); err != nil { return nil, err @@ -140,7 +104,7 @@ func (a Agent) CanisterStatus(arg0 CanisterStatusArgs) (*CanisterStatusResult, e // ClearChunkStore calls the "clear_chunk_store" method on the "ic" canister. func (a Agent) ClearChunkStore(arg0 ClearChunkStoreArgs) error { if err := a.a.Call( - a.canisterId, + arg0.CanisterId, "clear_chunk_store", []any{arg0}, []any{}, @@ -151,23 +115,14 @@ func (a Agent) ClearChunkStore(arg0 ClearChunkStoreArgs) error { } // CreateCanister calls the "create_canister" method on the "ic" canister. -func (a Agent) CreateCanister(arg0 CreateCanisterArgs) (*CreateCanisterResult, error) { - var r0 CreateCanisterResult - if err := a.a.Call( - a.canisterId, - "create_canister", - []any{arg0}, - []any{&r0}, - ); err != nil { - return nil, err - } - return &r0, nil +func (a Agent) CreateCanister(_ CreateCanisterArgs) (*CreateCanisterResult, error) { + return nil, fmt.Errorf("create_canister is not accepted as an ingress message") } // DeleteCanister calls the "delete_canister" method on the "ic" canister. func (a Agent) DeleteCanister(arg0 DeleteCanisterArgs) error { if err := a.a.Call( - a.canisterId, + arg0.CanisterId, "delete_canister", []any{arg0}, []any{}, @@ -180,7 +135,7 @@ func (a Agent) DeleteCanister(arg0 DeleteCanisterArgs) error { // DepositCycles calls the "deposit_cycles" method on the "ic" canister. func (a Agent) DepositCycles(arg0 DepositCyclesArgs) error { if err := a.a.Call( - a.canisterId, + arg0.CanisterId, "deposit_cycles", []any{arg0}, []any{}, @@ -191,17 +146,8 @@ func (a Agent) DepositCycles(arg0 DepositCyclesArgs) error { } // EcdsaPublicKey calls the "ecdsa_public_key" method on the "ic" canister. -func (a Agent) EcdsaPublicKey(arg0 EcdsaPublicKeyArgs) (*EcdsaPublicKeyResult, error) { - var r0 EcdsaPublicKeyResult - if err := a.a.Call( - a.canisterId, - "ecdsa_public_key", - []any{arg0}, - []any{&r0}, - ); err != nil { - return nil, err - } - return &r0, nil +func (a Agent) EcdsaPublicKey(_ EcdsaPublicKeyArgs) (*EcdsaPublicKeyResult, error) { + return nil, fmt.Errorf("ecdsa_public_key is not accepted as an ingress message") } // HttpRequest calls the "http_request" method on the "ic" canister. @@ -221,7 +167,7 @@ func (a Agent) HttpRequest(arg0 HttpRequestArgs) (*HttpRequestResult, error) { // InstallChunkedCode calls the "install_chunked_code" method on the "ic" canister. func (a Agent) InstallChunkedCode(arg0 InstallChunkedCodeArgs) error { if err := a.a.Call( - a.canisterId, + arg0.TargetCanister, "install_chunked_code", []any{arg0}, []any{}, @@ -234,7 +180,7 @@ func (a Agent) InstallChunkedCode(arg0 InstallChunkedCodeArgs) error { // InstallCode calls the "install_code" method on the "ic" canister. func (a Agent) InstallCode(arg0 InstallCodeArgs) error { if err := a.a.Call( - a.canisterId, + arg0.CanisterId, "install_code", []any{arg0}, []any{}, @@ -245,17 +191,8 @@ func (a Agent) InstallCode(arg0 InstallCodeArgs) error { } // NodeMetricsHistory calls the "node_metrics_history" method on the "ic" canister. -func (a Agent) NodeMetricsHistory(arg0 NodeMetricsHistoryArgs) (*NodeMetricsHistoryResult, error) { - var r0 NodeMetricsHistoryResult - if err := a.a.Call( - a.canisterId, - "node_metrics_history", - []any{arg0}, - []any{&r0}, - ); err != nil { - return nil, err - } - return &r0, nil +func (a Agent) NodeMetricsHistory(_ NodeMetricsHistoryArgs) (*NodeMetricsHistoryResult, error) { + return nil, fmt.Errorf("node_metrics_history is not accepted as an ingress message") } // ProvisionalCreateCanisterWithCycles calls the "provisional_create_canister_with_cycles" method on the "ic" canister. @@ -275,7 +212,7 @@ func (a Agent) ProvisionalCreateCanisterWithCycles(arg0 ProvisionalCreateCaniste // ProvisionalTopUpCanister calls the "provisional_top_up_canister" method on the "ic" canister. func (a Agent) ProvisionalTopUpCanister(arg0 ProvisionalTopUpCanisterArgs) error { if err := a.a.Call( - a.canisterId, + arg0.CanisterId, "provisional_top_up_canister", []any{arg0}, []any{}, @@ -287,36 +224,18 @@ func (a Agent) ProvisionalTopUpCanister(arg0 ProvisionalTopUpCanisterArgs) error // RawRand calls the "raw_rand" method on the "ic" canister. func (a Agent) RawRand() (*RawRandResult, error) { - var r0 RawRandResult - if err := a.a.Call( - a.canisterId, - "raw_rand", - []any{}, - []any{&r0}, - ); err != nil { - return nil, err - } - return &r0, nil + return nil, fmt.Errorf("raw_rand is not accepted as an ingress message") } // SignWithEcdsa calls the "sign_with_ecdsa" method on the "ic" canister. -func (a Agent) SignWithEcdsa(arg0 SignWithEcdsaArgs) (*SignWithEcdsaResult, error) { - var r0 SignWithEcdsaResult - if err := a.a.Call( - a.canisterId, - "sign_with_ecdsa", - []any{arg0}, - []any{&r0}, - ); err != nil { - return nil, err - } - return &r0, nil +func (a Agent) SignWithEcdsa(_ SignWithEcdsaArgs) (*SignWithEcdsaResult, error) { + return nil, fmt.Errorf("sign_with_ecdsa is not accepted as an ingress message") } // StartCanister calls the "start_canister" method on the "ic" canister. func (a Agent) StartCanister(arg0 StartCanisterArgs) error { if err := a.a.Call( - a.canisterId, + arg0.CanisterId, "start_canister", []any{arg0}, []any{}, @@ -329,7 +248,7 @@ func (a Agent) StartCanister(arg0 StartCanisterArgs) error { // StopCanister calls the "stop_canister" method on the "ic" canister. func (a Agent) StopCanister(arg0 StopCanisterArgs) error { if err := a.a.Call( - a.canisterId, + arg0.CanisterId, "stop_canister", []any{arg0}, []any{}, @@ -343,7 +262,7 @@ func (a Agent) StopCanister(arg0 StopCanisterArgs) error { func (a Agent) StoredChunks(arg0 StoredChunksArgs) (*StoredChunksResult, error) { var r0 StoredChunksResult if err := a.a.Call( - a.canisterId, + arg0.CanisterId, "stored_chunks", []any{arg0}, []any{&r0}, @@ -356,7 +275,7 @@ func (a Agent) StoredChunks(arg0 StoredChunksArgs) (*StoredChunksResult, error) // UninstallCode calls the "uninstall_code" method on the "ic" canister. func (a Agent) UninstallCode(arg0 UninstallCodeArgs) error { if err := a.a.Call( - a.canisterId, + arg0.CanisterId, "uninstall_code", []any{arg0}, []any{}, @@ -369,7 +288,7 @@ func (a Agent) UninstallCode(arg0 UninstallCodeArgs) error { // UpdateSettings calls the "update_settings" method on the "ic" canister. func (a Agent) UpdateSettings(arg0 UpdateSettingsArgs) error { if err := a.a.Call( - a.canisterId, + arg0.CanisterId, "update_settings", []any{arg0}, []any{}, @@ -383,7 +302,7 @@ func (a Agent) UpdateSettings(arg0 UpdateSettingsArgs) error { func (a Agent) UploadChunk(arg0 UploadChunkArgs) (*UploadChunkResult, error) { var r0 UploadChunkResult if err := a.a.Call( - a.canisterId, + arg0.CanisterId, "upload_chunk", []any{arg0}, []any{&r0}, diff --git a/request_test.go b/request_test.go index 3b29b0b..c774fc3 100644 --- a/request_test.go +++ b/request_test.go @@ -42,3 +42,16 @@ func TestNewRequestID(t *testing.T) { t.Error(h) } } + +func TestRequestID_Sign(t *testing.T) { + if h := fmt.Sprintf("%x", agent.NewRequestID(agent.Request{ + Type: agent.RequestTypeCall, + Sender: principal.AnonymousID, + CanisterID: principal.Principal{Raw: []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0xD2}}, + MethodName: "hello", + IngressExpiry: 1685570400000000000, + Arguments: []byte("DIDL\x00\xFD*"), + })); h != "1d1091364d6bb8a6c16b203ee75467d59ead468f523eb058880ae8ec80e2b101" { + t.Error(h) + } +} diff --git a/status_test.go b/status_test.go index f6d62a7..9e3b6de 100644 --- a/status_test.go +++ b/status_test.go @@ -7,10 +7,10 @@ import ( "github.com/aviate-labs/agent-go" ) -var ic0, _ = url.Parse("https://ic0.app/") +var ic0URL, _ = url.Parse("https://ic0.app/") func ExampleClient_Status() { - c := agent.NewClient(agent.ClientConfig{Host: ic0}) + c := agent.NewClient(agent.ClientConfig{Host: ic0URL}) status, _ := c.Status() fmt.Println(status.Version) // Output: