Meme Museum tutorial - 'exceed prepaid gas' - nearprotocol

Im getting this error. It seems to happen no matter how much gas I give it. Can someone help or advise what I am doing wrong? Thanks
Scheduling a call: museum.testnet.add_meme({"meme" : "andrew", "title" : "sweats", "data" : "https://9gag.com/gag/aVxM0B2", "category" : 4}) with attached 6 NEAR
Doing account.functionCall()
Receipts: BuNWjPmKBojGbjUs86EEpX1xrvC6AG5GacxX5xmTzSkk, 5PAK416Wn1F5AzHHz28fNa2dbHzWHFzKg2UoKCStfZ3U
Log [museum.testnet]: attempting to create meme
Failure [museum.testnet]: Error: {"index":0,"kind":{"ExecutionError":"Exceeded the prepaid gas."}}
Transaction 87djyBrCwgubEfsta68xPeRTy6VKShXMWEroSkvjDSY3 had 30000000000000 of attached gas but used 2428128941862 of gas
View this transaction in explorer: https://explorer.testnet.near.org/transactions/87djyBrCwgubEfsta68xPeRTy6VKShXMWEroSkvjDSY3```

In order to execute this properly you need to have both the --amount 3 and the --gas 300000000000000 parameters.
near call museum.testnet add_meme '{ "meme": "coe", \
"title": "roncoe", "data": "https://9gag.com/gag/ad8K0vj", \
"category": 4 }' --accountId youraccountid.testnet \
--gas 300000000000000 --amount 3

Try attaching gas instead of deposit. Here's an example using the CLI:
near call museum.testnet add_meme --gas 300000000000000 --accountId=youraccount.testnet '{
"meme": "bob",
"title": "blabla",
"data": "https://9gag.com/gag/ad8K0vj",
"category": 4
}'

Related

NEAR "ExecutionError":"Exceeded the prepaid gas."

I'm going through the tutorial in https://near.academy/near101/chapter-6
One of the steps is to run this command (but with my account):
near call museum.testnet add_meme \
'{"meme" : "bob", "title" : "god", "data" : "https://9gag.com/gag/ad8K0vj", "category" : 4}' \
--accountId YOUR_ACCOUNT_NAME.testnet --amount 3
I keep getting errors like:
Log [museum.testnet]: attempting to create meme
Failure [museum.testnet]: Error: {"index":0,"kind":{"ExecutionError":"Exceeded the prepaid gas."}}
Transaction 9F9VUps6nN4myC8wzBUb1W1GTR4xV5WE had 30000000000000 of attached gas but used 2428115526258 of gas
It's a confusing error message because 30,000,000,000,000 > 2,428,178,132,410.
I have also tried running the command with --amount 4 instead, but I got the same error.
What am I doing wrong?
Benji at https://discord.com/channels/490367152054992913/542945453533036544/912840246524260355 suggested that instead of using --amount 3 I use --amount 3 --gas=75000000000000, which worked.
If you are using windows then you should use backslash , before every ".
near call museum.testnet add_meme '{"meme" : "Bob", "title" : "Jokes", "data" : "https://9gag.com/gag/aAGQ97L", "category" : 4}' --accountId NAME.testnet --amount 3 --gas=75000000000000

Autocompletion elasticsearch

I'm following along with the tutorial for elasticsearch's completion suggester here. It's pretty easy to get going. But I'm unable to get completions for more than one word. In the example single incomplete words give great results, e.g
"Nir" -> "options":[{"text":"Nevermind Nirvana..."
"Nev" -> "options":[{"text":"Nevermind Nirvana..."
But the following fail:
"Nirvana Nev" -> Nothing!
"Nevermind Nir" -> Nothing!
I can get it to work by populating combinatorial options e.g
curl -X PUT "localhost:9200/music/_doc/1?refresh" -H 'Content-Type: application/json' -d'
{
"suggest" : {
"input": [ "Nevermind", "Nirvana", "Nirvana Nevermind", "Nevermind Nirvana" ],
"weight" : 34
},
"title" : "Nevermind by Nirvana"
}
'
But this approach will soon lead to massive variants of text added to the input.
There must be a better way?

Error handling with curl and elasticsearch

I'm currently developing bash scripts that use elasticsearch and I need a good error-handling.
In this situation I try to add a document to elasticsearch and check if the operation succeeded.
At first I naively tried this :
response=$(curl -XPOST 'http://localhost:9200/indexation/document' -d '
{
"content":"'"$txt"'",,
"date_treatment":"'"$(date +%Y-%m-%d)"'"
}') && echo ok || echo fail
But curl doesn't work that way and still returns success (0 - which is actually logical) even though the json request is obviously incorrect (note the double comma on line 3) and elasticsearch displays errors.
So the answer isn't there. Now I think I should analyze the variable $response to catch errors (grep ?). I post this question to get hints or solutions on the way to do this in a reliable way and to make sure I'm not missing an obvious solution (maybe a curl option I don't know ?).
Additional useful things
Parsing JSON with Unix tools
Examples of the content of $response :
success :
{
"_id": "AVQz7Fg0nF90YvJIX_2C",
"_index": "indexation",
"_shards": {
"failed": 0,
"successful": 1,
"total": 1
},
"_type": "document",
"_version": 1,
"created": true
}
error :
{
"error": {
"caused_by": {
"reason": "json_parse_exception: Unexpected character (',' (code 44)): was expecting either valid name character (for unquoted name) or double-quote (for quoted) to start field name\n at [Source: org.elasticsearch.common.io.stream.InputStreamStreamInput#139163f; line: 3, column: 17]",
"type": "json_parse_exception"
},
"reason": "failed to parse",
"root_cause": [
{
"reason": "json_parse_exception: Unexpected character (',' (code 44)): was expecting either valid name character (for unquoted name) or double-quote (for quoted) to start field name\n at [Source: org.elasticsearch.common.io.stream.InputStreamStreamInput#139163f; line: 3, column: 17]",
"type": "json_parse_exception"
}
],
"type": "mapper_parsing_exception"
},
"status": 400
}
A simple workaround is to use the -f/--fail option.
As per documentation :
(HTTP) Fail silently (no output at all) on server errors. This is
mostly done to better enable scripts etc to better deal with failed
attempts. In normal cases when an HTTP server fails to deliver a
document, it returns an HTML document stating so (which often also
describes why and more). This flag will prevent curl from outputting
that and return error 22.
This method is not fail-safe and there are occasions where
non-successful response codes will slip through, especially when
authentication is involved (response codes 401 and 407).
example:
response=$(curl -XPOST 'http://localhost:9200/indexation/document' -d '
{
"content":"'"$txt"'",,
"date_treatment":"'"$(date +%Y-%m-%d)"'"
}' -f ) && echo ok || echo fail

Couchdb view Queries

Could you please help me in creating a view. Below is the requirement
select * from personaccount where name="srini" and user="pup" order by lastloggedin
I have to send name and user as input to the view and the data should be sorted by lastloggedin.
Below is the view I have created but it is not working
{
"language": "javascript",
"views": {
"sortdatetimefunc": {
"map": "function(doc) {
emit({
lastloggedin: doc.lastloggedin,
name: doc.name,
user: doc.user
},doc);
}"
}
}
}
And this the curl command iam using:
http://uta:password#localhost:5984/personaccount/_design/checkdatesorting/_view/sortdatetimefunc?key={\"name:srini\",\"user:pup\"}
My Questions are
As sorting will be done on key and I want it on lastloggedin so I have given that also in emit function.
But iam passing name and user only as parameters. Do we need to pass all the parameters which we give it in key?
First of all I want to convey to you for the reply, I have done the same and iam getting errors. Please help
Could you please try this on your PC, iam posting all the commands :
curl -X PUT http://uta:password#localhost:5984/person-data
curl -X PUT http://uta:password#localhost:5984/person-data/srini -d '{"Name":"SRINI", "Idnum":"383896", "Format":"NTSC", "Studio":"Disney", "Year":"2009", "Rating":"PG", "lastTimeOfCall": "2012-02-08T19:44:37+0100"}'
curl -X PUT http://uta:password#localhost:5984/person-data/raju -d '{"Name":"RAJU", "Idnum":"456787", "Format":"FAT", "Studio":"VFX", "Year":"2010", "Rating":"PG", "lastTimeOfCall": "2012-02-08T19:50:37+0100"}'
curl -X PUT http://uta:password#localhost:5984/person-data/vihar -d '{"Name":"BALA", "Idnum":"567876", "Format":"FAT32", "Studio":"YELL", "Year":"2011", "Rating":"PG", "lastTimeOfCall": "2012-02-08T19:55:37+0100"}'
Here's the view as you said I created :
{
"_id": "_design/persondestwo",
"_rev": "1-0d3b4857b8e6c9e47cc9af771c433571",
"language": "javascript",
"views": {
"personviewtwo": {
"map": "function (doc) {\u000a emit([ doc.Name, doc.Idnum, doc.lastTimeOfCall ], null);\u000a}"
}
}
}
I have fired this command from curl command :
curl -X GET http://uta:password#localhost:5984/person-data/_design/persondestwo/_view/personviewtwo?startkey=["SRINI","383896"]&endkey=["SRINI","383896",{}]descending=true&include_docs=true
I got this error :
[4] 3000
curl: (3) [globbing] error: bad range specification after pos 99
[5] 1776
[6] 2736
[3] Done descending=true
[4] Done(3) curl -X GET http://uta:password#localhost:5984/person-data/_design/persondestwo/_view/personviewtwo?startkey=["SRINI","383896"]
[5] Done endkey=["SRINI","383896"]
I am not knowing what this error is.
I have also tried passing the parameters the below way and it is not helping
curl -X GET http://uta:password#localhost:5984/person-data/_design/persondestwo/_view/personviewtwo?key={\"Name\":\"SRINI\",\"Idnum\": \"383896\"}&descending=true
But I get different errors on escape sequences
Overall I just want this query to be satisfied through the view :
select * from person-data where Name="SRINI" and Idnum="383896" orderby lastTimeOfCall
My concern is how to pass the multiple parameters from curl command as I get lot of errors if I do the above way.
First off, you need to use an array as your key. I would use:
function (doc) {
emit([ doc.name, doc.user, doc.lastLoggedIn ], null);
}
This basically outputs all the documents in order by name, then user, then lastLoggedIn. You can use the following URL to query.
/_design/checkdatesorting/_view/sortdatetimefunc?startkey=["srini","pup"]&endkey=["srini","pup",{}]&include_docs=true
Second, notice I did not output doc as the value of your query. It takes up much more disk space, especially if your documents are fairly large. Just use include_docs=true.
Lastly, refer to the CouchDB Wiki, it's pretty helpful.
I just stumbled upon this question. The errors you are getting are caused by not escaping this command:
curl -X GET http://uta:password#localhost:5984/person-data/_design/persondestwo/_view/personviewtwo?startkey=["SRINI","383896"]&endkey=["SRINI","383896",{}]descending=true&include_docs=true
The & character has a special meaning on the command-line and should be escaped when part of an actual parameter.
So you should put quotes around the big URL, and escape the quotes inside it:
curl -X GET "http://uta:password#localhost:5984/person-data/_design/persondestwo/_view/personviewtwo?startkey=[\"SRINI\",\"383896\"]&endkey=[\"SRINI\",\"383896\",{}]descending=true&include_docs=true"

Using json_spec gem's 'at "path" should include:' step is not working as I would expect

(apologies in advance for the cucumber steps, they need to be cleaned up a fair bit to flow better)
I am using a combination of Cucumber, along with the rest-client, and json_spec gems to create a test suite for a restful API. The approach is similar to that given in the Cucumber Book Note that in this case, since the 'customer' is a developer, the 'language of the business' is far more technical than you would normally express in cucumber scenarios
I am having a problem with the json_spec cucumber step "Then the JSON at "path" should include:"
My scenario looks like this
Scenario Outline: GET to OR Packages for specific package uuid returns proper data
Given I create a request body from the following JSON data
"""
{
"package":
{
"name": "anothertestpackage",
"description": "This is a test, testing 4 5 6",
"package_type" : <package_type>,
"duration": 30,
"start_date": "2012-03-01T08:00:00Z"
}
}
"""
And I have the URI for a new: package made in: OR from the request body
When I make a: GET request to the URI for: my new package with no query string
Then the JSON at "package" should include:
"""
{
"name": "anothertestpackage",
"description": "This is a test, testing 4 5 6",
"package_type" : <package_type>,
"duration": 30,
"start_date": "2012-03-01T08:00:00Z"
}
"""
Examples:
| package_type |
| "IMPRESSIONS" |
| "CLICKS" |
| "LEADS" |
And the contents of last_json are like this at the point the Then step is executed
{
"package": {
"status": "NEW",
"account": {
"resource_uri": "/api/v0001/accounts/fecdbb85a3584ca59820a321c3c2767d"
},
"name": "anothertestpackage",
"package_type": "IMPRESSIONS",
"margin_goal": "0.5000",
"duration": 30,
"resource_uri": "/api/v0001/packages/fecdbb85a3584ca59820a321c3c2767d/feea333776c9454c92edab8e73628cbd",
"start_date": "2012-03-01T08:00:00Z",
"description": "This is a test, testing 4 5 6"
}
}
I should think the step would pass, but I'm getting this error instead
Expected included JSON at path "package" (RSpec::Expectations::ExpectationNotMetError)
features\OR\API\OR_API_Packages.feature:70:in `Then the JSON at "package" should include:'
It is unclear what that error is telling me in terms of what is wrong. Is this user error? should I be using a different means to determine if the expected key:value pairs are present in the JSON returned by the API? I don't really see any examples of doing this kind of comparison in your feature files for the gem, so it is difficult to know if this is not what include was intended for.
Heh just got an answer from one of the gem authors via another venue. Will post it here
Include was intended more for simple value inclusion, mostly in
arrays. If an API index response returned an array of objects, you
could assert that the array includes one whole, identical object.
Check out the matcher specs for examples.
For what you're doing, I'd break it out into separate steps:
Then the JSON at "package/name" should be "anothertestpackage"
And the JSON at "package/description" should be "This is a test, testing 4 5 6"
And the JSON at "package/package_type" should be <package_type>
And the JSON at "package/duration" should be 30
And the JSON at "package/start_date" should be "2012-03-01T08:00:00Z"
Or you could make use of a table format to make that more succinct
such as
Then the JSON at "package" should have the following:
| name | "anothertestpackage" |
| description | "This is a test, testing 4 5 6" |
| package_type | <package_type> |
| duration | 30 |
| start_date | "2012-03-01T08:00:00Z" |
I hope that helps! Thanks for the question.
Indeed it did help very much, thank you 'laserlemon'

Resources