1

I am implementing a smart contract according to the psp34 openbrush standard. Now I want to do some testing. I want to mint a token and then use it in some methods. Some of the methods of my smart contract require, that the caller is either the owner of the token or approved by the owner. How can I change from the creator (the account that mints the token) of the token to another account that then uses the token? For example when testing with truffle you can use [deployer, investor] and then specify the caller with {from: investor}. Is something similar possible here?

1 Answer 1

1

I found examples of how to test for this and more use cases in the openbrush github repo. Here is the example that I needed for my question.

Here is what the important parts are:

use openbrush::{
    contracts::psp34::*,
    test_utils::{
        accounts,
        change_caller,
    }
};
...
#[ink::test]
fn transfer_token() {
    let accounts = accounts();
    ...
    let owner = accounts.alice;
    let spender = accounts.bob;
    ...
    change_caller(spender);
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.