From 243dad1fe9d8062b6be10c6971812882661ba69f Mon Sep 17 00:00:00 2001 From: Trevor French Date: Wed, 24 Apr 2024 12:28:01 -0400 Subject: [PATCH 1/3] updating tests and examples to accomodate rate limiting --- R/solana.R | 39 +++++++++++------ tests/testthat/test-solana.R | 82 ++++++++++++++++++++++++++++++------ 2 files changed, 96 insertions(+), 25 deletions(-) diff --git a/R/solana.R b/R/solana.R index cc254b0..994a4bf 100644 --- a/R/solana.R +++ b/R/solana.R @@ -7,10 +7,11 @@ #' @export #' #' @examples +#' \dontrun{ #' url <- "https://api.devnet.solana.com" #' request_body <- #' solana_assemble_request_body('"2.0"', 'null', '"getBlockHeight"', NULL) -#' data <- solana_api_call(url, request_body) +#' data <- solana_api_call(url, request_body)} solana_api_call <- function(url, request_body) { headers <- c("Content-Type" = "application/json") @@ -76,12 +77,13 @@ solana_assemble_list <- function(character_vector) { #' @export #' #' @examples +#' \dontrun{ #' limit <- solana_assemble_key_pair('limit', NULL) #' character_vector <- c(limit) #' config_object <- solana_assemble_list(character_vector) #' address <- "Vote111111111111111111111111111111111111111" #' params <- paste('["', address, '", {', config_object, '}]', sep = '') -#' solana_assemble_request_body('"2.0"', 'null', '"getSignaturesForAddress"', params) +#' solana_assemble_request_body('"2.0"', 'null', '"getSignaturesForAddress"', params)} solana_assemble_request_body <- function(jsonrpc, id, method, params) { @@ -108,9 +110,10 @@ solana_assemble_request_body <- #' @export #' #' @examples +#' \dontrun{ #' url <- "https://api.devnet.solana.com" #' address <- "Vote111111111111111111111111111111111111111" -#' data <- solana_get_signature_for_address(url,address) +#' data <- solana_get_signature_for_address(url,address)} solana_get_signature_for_address <- function(url, address, limit = NULL) { @@ -133,9 +136,10 @@ solana_get_signature_for_address <- #' @export #' #' @examples +#' \dontrun{ #' url <- "https://api.devnet.solana.com" #' pubkey <- "vines1vzrYbzLMRdu58ou5XTby4qAqVRLmqo36NKPTg" -#' data <- solana_get_account_info(url, pubkey) +#' data <- solana_get_account_info(url, pubkey)} solana_get_account_info <- function(url, pubkey) { params <- paste('["', pubkey, '"]', sep = '') @@ -153,8 +157,9 @@ solana_get_account_info <- function(url, pubkey) { #' @export #' #' @examples +#' \dontrun{ #' url <- "https://api.devnet.solana.com" -#' data <- solana_get_block_height(url) +#' data <- solana_get_block_height(url)} solana_get_block_height <- function(url) { request_body <- @@ -171,8 +176,9 @@ solana_get_block_height <- function(url) { #' @export #' #' @examples +#' \dontrun{ #' url <- "https://api.devnet.solana.com" -#' data <- solana_get_health(url) +#' data <- solana_get_health(url)} solana_get_health <- function(url) { request_body <- @@ -189,8 +195,9 @@ solana_get_health <- function(url) { #' @export #' #' @examples +#' \dontrun{ #' url <- "https://api.devnet.solana.com" -#' data <- solana_get_version(url) +#' data <- solana_get_version(url)} solana_get_version <- function(url) { request_body <- @@ -226,8 +233,9 @@ solana_get_supply <- function(url) { #' @export #' #' @examples +#' \dontrun{ #' url <- "https://api.devnet.solana.com" -#' data <- solana_get_identity(url) +#' data <- solana_get_identity(url)} solana_get_identity <- function(url) { request_body <- @@ -244,8 +252,9 @@ solana_get_identity <- function(url) { #' @export #' #' @examples +#' \dontrun{ #' url <- "https://api.devnet.solana.com" -#' data <- solana_get_inflation_rate(url) +#' data <- solana_get_inflation_rate(url)} solana_get_inflation_rate <- function(url) { request_body <- @@ -262,8 +271,9 @@ solana_get_inflation_rate <- function(url) { #' @export #' #' @examples +#' \dontrun{ #' url <- "https://api.devnet.solana.com" -#' data <- solana_get_genesis_hash(url) +#' data <- solana_get_genesis_hash(url)} solana_get_genesis_hash <- function(url) { request_body <- @@ -280,8 +290,9 @@ solana_get_genesis_hash <- function(url) { #' @export #' #' @examples +#' \dontrun{ #' url <- "https://api.devnet.solana.com" -#' data <- solana_get_recent_prioritization_fees(url) +#' data <- solana_get_recent_prioritization_fees(url)} solana_get_recent_prioritization_fees <- function(url) { request_body <- @@ -299,8 +310,9 @@ solana_get_recent_prioritization_fees <- function(url) { #' @export #' #' @examples +#' \dontrun{ #' url <- "https://api.devnet.solana.com" -#' data <- solana_get_slot(url) +#' data <- solana_get_slot(url)} solana_get_slot <- function(url) { request_body <- @@ -319,9 +331,10 @@ solana_get_slot <- function(url) { #' @export #' #' @examples +#' \dontrun{ #' url <- "https://api.devnet.solana.com" #' slot <- solana_get_slot(url) -#' data <- solana_get_block(url, slot) +#' data <- solana_get_block(url, slot)} solana_get_block <- function(url, slot) { params <- paste('[', slot, ', diff --git a/tests/testthat/test-solana.R b/tests/testthat/test-solana.R index 9aa4975..8e84bc4 100644 --- a/tests/testthat/test-solana.R +++ b/tests/testthat/test-solana.R @@ -1,70 +1,128 @@ test_that('the "solana_get_signature_for_address" function returns a list', { url <- "https://api.devnet.solana.com" address <- "Vote111111111111111111111111111111111111111" - data <- solana_get_signature_for_address(url, address) + data <- tryCatch( + solana_get_signature_for_address(url, address), + error = function(c) geterrmessage() + ) + if (data[1] == "Request failed with status code: 429") {skip("Rate Limit")} expect_type(data, 'list') }) test_that('the "solana_get_account_info" function returns a list', { + skip_on_cran() url <- "https://api.devnet.solana.com" pubkey <- "vines1vzrYbzLMRdu58ou5XTby4qAqVRLmqo36NKPTg" - data <- solana_get_account_info(url, pubkey) + data <- tryCatch( + solana_get_account_info(url, pubkey), + error = function(c) geterrmessage() + ) + if (data[1] == "Request failed with status code: 429") {skip("Rate Limit")} expect_type(data, 'list') }) test_that('the "solana_get_account_info" function returns a list', { + skip_on_cran() url <- "https://api.devnet.solana.com" - data <- solana_get_block_height(url) + data <- tryCatch( + solana_get_block_height(url), + error = function(c) geterrmessage() + ) + if (data[1] == "Request failed with status code: 429") {skip("Rate Limit")} expect_type(data, 'integer') }) test_that('the "solana_get_health" function returns a character', { + skip_on_cran() url <- "https://api.devnet.solana.com" - data <- solana_get_health(url) + data <- tryCatch( + solana_get_health(url), + error = function(c) geterrmessage() + ) + if (data[1] == "Request failed with status code: 429") {skip("Rate Limit")} expect_type(data, 'character') }) test_that('the "solana_get_version" function returns a list', { + skip_on_cran() url <- "https://api.devnet.solana.com" - data <- solana_get_version(url) + data <- tryCatch( + solana_get_version(url), + error = function(c) geterrmessage() + ) + if (data[1] == "Request failed with status code: 429") {skip("Rate Limit")} expect_type(data, 'list') }) test_that('the "solana_get_supply" function returns a list', { + skip_on_cran() url <- "https://api.devnet.solana.com" - data <- solana_get_supply(url) + data <- tryCatch( + solana_get_supply(url), + error = function(c) geterrmessage() + ) + if (data[1] == "Request failed with status code: 429") {skip("Rate Limit")} expect_type(data, 'list') }) test_that('the "solana_get_identity" function returns a character', { + skip_on_cran() url <- "https://api.devnet.solana.com" - data <- solana_get_identity(url) + data <- tryCatch( + solana_get_identity(url), + error = function(c) geterrmessage() + ) + if (data[1] == "Request failed with status code: 429") {skip("Rate Limit")} expect_type(data, 'character') }) test_that('the "solana_get_inflation_rate" function returns a list', { + skip_on_cran() url <- "https://api.devnet.solana.com" - data <- solana_get_inflation_rate(url) + data <- tryCatch( + solana_get_inflation_rate(url), + error = function(c) geterrmessage() + ) + if (data[1] == "Request failed with status code: 429") {skip("Rate Limit")} expect_type(data, 'list') }) test_that('the "solana_get_genesis_hash" function returns a character', { + skip_on_cran() url <- "https://api.devnet.solana.com" - data <- solana_get_genesis_hash(url) + data <- tryCatch( + solana_get_genesis_hash(url), + error = function(c) geterrmessage() + ) + if (data[1] == "Request failed with status code: 429") {skip("Rate Limit")} expect_type(data, 'character') }) test_that('the "solana_get_slot" function returns an integer and the "solana_get_block" function returns a list', { + skip_on_cran() url <- "https://api.devnet.solana.com" - slot <- solana_get_slot(url) - data <- solana_get_block(url, slot) + slot <- tryCatch( + solana_get_slot(url), + error = function(c) geterrmessage() + ) + if (slot[1] == "Request failed with status code: 429") {skip("Rate Limit")} + data <- tryCatch( + solana_get_block(url, slot), + error = function(c) geterrmessage() + ) + if (data[1] == "Request failed with status code: 429") {skip("Rate Limit")} expect_type(slot, 'integer') expect_type(data, 'list') }) test_that('the "solana_get_recent_prioritization_fees" function returns a list', { + skip_on_cran() url <- "https://api.devnet.solana.com" - data <- solana_get_recent_prioritization_fees(url) + data <- tryCatch( + solana_get_recent_prioritization_fees(url), + error = function(c) geterrmessage() + ) + if (data[1] == "Request failed with status code: 429") {skip("Rate Limit")} expect_type(data, 'list') }) From 0e59b88c4f9ba434721df8d3914b86a40da1fb7c Mon Sep 17 00:00:00 2001 From: Trevor French Date: Wed, 24 Apr 2024 12:29:01 -0400 Subject: [PATCH 2/3] updating tests and examples to accomodate rate limiting --- tests/testthat/test-solana.R | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/tests/testthat/test-solana.R b/tests/testthat/test-solana.R index 8e84bc4..589fe93 100644 --- a/tests/testthat/test-solana.R +++ b/tests/testthat/test-solana.R @@ -10,7 +10,6 @@ test_that('the "solana_get_signature_for_address" function returns a list', { }) test_that('the "solana_get_account_info" function returns a list', { - skip_on_cran() url <- "https://api.devnet.solana.com" pubkey <- "vines1vzrYbzLMRdu58ou5XTby4qAqVRLmqo36NKPTg" data <- tryCatch( @@ -22,7 +21,6 @@ test_that('the "solana_get_account_info" function returns a list', { }) test_that('the "solana_get_account_info" function returns a list', { - skip_on_cran() url <- "https://api.devnet.solana.com" data <- tryCatch( solana_get_block_height(url), @@ -33,7 +31,6 @@ test_that('the "solana_get_account_info" function returns a list', { }) test_that('the "solana_get_health" function returns a character', { - skip_on_cran() url <- "https://api.devnet.solana.com" data <- tryCatch( solana_get_health(url), @@ -44,7 +41,6 @@ test_that('the "solana_get_health" function returns a character', { }) test_that('the "solana_get_version" function returns a list', { - skip_on_cran() url <- "https://api.devnet.solana.com" data <- tryCatch( solana_get_version(url), @@ -55,7 +51,6 @@ test_that('the "solana_get_version" function returns a list', { }) test_that('the "solana_get_supply" function returns a list', { - skip_on_cran() url <- "https://api.devnet.solana.com" data <- tryCatch( solana_get_supply(url), @@ -66,7 +61,6 @@ test_that('the "solana_get_supply" function returns a list', { }) test_that('the "solana_get_identity" function returns a character', { - skip_on_cran() url <- "https://api.devnet.solana.com" data <- tryCatch( solana_get_identity(url), @@ -77,7 +71,6 @@ test_that('the "solana_get_identity" function returns a character', { }) test_that('the "solana_get_inflation_rate" function returns a list', { - skip_on_cran() url <- "https://api.devnet.solana.com" data <- tryCatch( solana_get_inflation_rate(url), @@ -88,7 +81,6 @@ test_that('the "solana_get_inflation_rate" function returns a list', { }) test_that('the "solana_get_genesis_hash" function returns a character', { - skip_on_cran() url <- "https://api.devnet.solana.com" data <- tryCatch( solana_get_genesis_hash(url), @@ -100,7 +92,6 @@ test_that('the "solana_get_genesis_hash" function returns a character', { test_that('the "solana_get_slot" function returns an integer and the "solana_get_block" function returns a list', { - skip_on_cran() url <- "https://api.devnet.solana.com" slot <- tryCatch( solana_get_slot(url), @@ -117,7 +108,6 @@ test_that('the "solana_get_slot" function returns an integer and the }) test_that('the "solana_get_recent_prioritization_fees" function returns a list', { - skip_on_cran() url <- "https://api.devnet.solana.com" data <- tryCatch( solana_get_recent_prioritization_fees(url), From f2a0f327144c556d3751a917b68675d1e2377ce5 Mon Sep 17 00:00:00 2001 From: Trevor French Date: Wed, 24 Apr 2024 12:47:49 -0400 Subject: [PATCH 3/3] updating tests and examples to accomodate rate limiting --- R/solana.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/solana.R b/R/solana.R index 994a4bf..0994097 100644 --- a/R/solana.R +++ b/R/solana.R @@ -21,7 +21,7 @@ solana_api_call <- function(url, request_body) { if (httr::status_code(response) == 200) { return(httr::content(response)) } else { - print(httr::content(response, as = "text")) + # print(httr::content(response, as = "text")) stop("Request failed with status code: ", httr::status_code(response)) }