Error on returning environmental account id's - nearprotocol

If I have the following method to test predecessor_account_id behaviour
pub fn get_pred_acc(&self) -> (String {
let prev_acc = env::predecessor_account_id().to_string();
return prev_acc;
}
And try to call this from frontend
const contract = await this.near.loadContract(window.nearConfig.contractName, {
viewMethods: ["get_pred_acc", ],
changeMethods: [],
sender: this.accountId,
});
const acc = await contract.get_pred_acc();
I get the following error:
Uncaught (in promise) Error: Querying call/flux-protocol/get_account_id failed: wasm execution failed with error: FunctionCallError(HostError(ProhibitedInView("predecessor_account_id"))).
{ "error": "wasm execution failed with error: FunctionCallError(HostError(ProhibitedInView(\"predecessor_account_id\")))",
"logs": []
}

That's expected behavior for the view calls.
The view calls don't have certain context information such calls are not part of an actual transaction.
Currently, the best option to see which methods are prohibited in the view calls is to take a look at the test: https://github.com/nearprotocol/nearcore/blob/master/runtime/near-vm-logic/tests/test_view_method.rs#L19-L43
To summarize:
previous account information and keys (signer, predecessor and signer_public_key)
gas information
all promise methods, cause they involve other contracts

Related

Anchor,Solana -> failed to send transaction: Transaction simulation failed Custom Error 0x0

I am trying to build a simple coin flip game in solana.
Full code here
I get this error:
Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: custom program error: 0x0
I followed some tutorials on how to use PDA's but couldn't find a report/workaround to an error as such.
Tests are running on localhost
I did some research and it might be that the account was already initialized ( maybe, no idea)
the part that is giving the error:
try {
await program.rpc.initialize(bump,
{
accounts: {
treasury: treasuryPda, // publickey for our new account
user: provider.wallet.publicKey,
systemProgram: SystemProgram.programId // just for Anchor reference
},
});
} catch (error) {
console.log("Transaction error: ", error);
console.log("blabla:", error.toString());
}

nightwatchjs saveScreenshot giving TypeError: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView

I am working on an automation prototype using Nightwatch js and when I am trying to save screenshot, it is giving below error
Error while running .getScreenshot() protocol action: An unknown
server-side error occurred while processing the command. – An unknown
server-side error occurred while proces...
TEST FAILURE: 1 error during execution; 0 tests failed, 0 passed
(10.032s)
TypeError: The "data" argument must be of type string or an instance
of Buffer, TypedArray, or DataView. Received an instance of Object
at Object.writeFile (fs.js:1487:5)
at FSReqCallback.oncomplete (fs.js:180:23)
FAILED: 1 errors and 1 passed (9.662s)
relevant data for nightwatch.config.js:
test_settings: {
"screenshots": {
"enabled": true, // if you want to keep screenshots
"path": './screenshots' // save screenshots here
},
test file data:
.pause(3000).saveScreenshot('./screnshots/test.png');
Nightwatch version: "1.5.1"
please note that due to office policy cannot paste complete testcase data here.

Receiving error: Class Action is missing in schema: actions.actions

I'm trying to broadcast transaction having following actions:
actions: [
transactions.createAccount(),
transactions.transfer(new BN(swapParams.value.toFixed())),
transactions.deployContract(new Uint8Array(bytecode)),
transactions.functionCall(
ABI.init.method,
{
secretHash: Buffer.from(swapParams.secretHash, 'hex').toString('base64'),
expiration: `${toNearTimestampFormat(swapParams.expiration)}`,
buyer: swapParams.recipientAddress
},
new BN(ABI.init.gas),
new BN(0)
)
]
But when I invoke
const tx = await from.signAndSendTransaction(addressToString(options.to), options.actions)
I receive following callstack:
Any idea what might be the reason?
I'm using:
near-js-api: 0.39.0
According to the documentation, source code, and defined types signAndSendTransaction should take a single argument (an object with receiverId and actions fields):
const tx = await from.signAndSendTransaction({
receiverId: addressToString(options.to),
actions: options.actions
})
Was there an example/doc that mislead you, so you arrived with this function call interface? We should fix that.

near-sdk-rs: view call fails trying to call to attached_deposit, but nothing in the contract seems to be looking at the attached_deposit

I have the following method in my contract:
#[near_bindgen]
#[derive(BorshDeserialize, BorshSerialize, PanicOnDefault)]
pub struct MyContract {
...,
}
#[near_bindgen]
impl MyContract {
...
pub fn is_account_whitelisted(account_id: &AccountId) -> bool {
Self::account_task_ordinals_map().contains_key(account_id)
}
fn account_task_ordinals_map() -> LookupMap<AccountId, Option<u32>> {
LookupMap::new(b"o".to_vec())
}
...
}
is_account_whitelisted is intended to be used as a view method. I then later use it from near-api-js in the following way:
window.contract = await near.loadContract(nearConfig.contractName, {
viewMethods: ['is_account_whitelisted', ...],
changeMethods: [...],
sender: window.walletAccount.getAccountId()
});
...
window.contract.is_account_whitelisted({'account_id': window.walletAccount.getAccountId()}).then(m => console.log(m));
and it fails with
...
FunctionCallError(HostError(ProhibitedInView { method_name: "attached_deposit" })).
{
"error": "wasm execution failed with error: FunctionCallError(HostError(ProhibitedInView { method_name: \"attached_deposit\" }))",
...
Do I need to annotate the method in some way, am I not calling it right, or is there something that I use in the method that causes the call to the attached_deposit?
Thanks to the Evgeny's comment, I found out that presently a method is only considered a view method if it has a immutable self as the first argument. Here's the link to the relevant code in near-sdk-rs:
https://github.com/near/near-sdk-rs/blob/18b8f8f3b672bfb422ff83a5138395f7e24dd70d/near-sdk-core/src/info_extractor/attr_sig_info.rs#L109
It is likely to be fixed soon, but in the meantime the way to address it is to add the immutable self as the first argument.

How to unit test graphql query/mutation error with Mocha and Chai?

Since graphql error is not an standard Error. It's a GraphQLError
I can't figure out how to write unit test when graphql query/mutation throw an exception.
Here is my try:
it('should throw an error when lack of "id" argument for user query', async () => {
const body = {
query: `
query user{
user {
id
name
}
}
`
};
try {
const actualValue = await rp(body);
} catch (err) {
logger.error(err);
}
// logger.info(actualValue);
expect(1).to.be.equal(1);
// expect(actualValue).to.throw()
});
I found some tests in graphql.js repo. https://github.com/graphql/graphql-js/blob/master/src/tests/starWarsQuery-test.js#L393
But I think the way they test the query/mutation error is not correct.
They just do a deep equal with the error. But before running the test suites, how do I know the error data structure like locations: [{ line: 5, column: 13 }],? Maybe I should use snapshot testing so that I don't need to know the error data structure?
Check this package https://github.com/EasyGraphQL/easygraphql-tester there is an example with mocha and chai on the documentation

Resources