Different sender with AEproject tests

I’m playing with the BasicNFT contract in AEproject and get stuck when trying to invoke an entrypoint as a different caller. What I do is this:

await instance.burn(tokenID, {caller: receiverKeyPair.publicKey})

I also tried address and sender instead of caller, no luck. I keep being treated on the error Owner of token is not you! from the contract.

I can’t find anything in the AEproject documentation nor on the document hub either. Anyone able to tell me how to do this?

2 Likes

you have to change the keypair of the instance you are using or create a separate instance with different keypair to sign the tx

2 Likes

I’m still stuck with this issue.

The deployer and instance are created like this:

    before(async () => {
        deployer = new Deployer('local', ownerKeyPair.secretKey)
    })

    it('Deploying NFT Contract', async () => {
        const deployedPromise = deployer.deploy(CONTRACT_PATH, [ "Test token", "TST" ]) // Deploy it

        await assert.isFulfilled(deployedPromise, 'Could not deploy the NFT Smart Contract'); // Check whether it's deployed
        instance = await Promise.resolve(deployedPromise)
        console.log(deployer)
    })

deployer has a field keypair, but instance doesn’t.

However, changing that value of deployer makes no difference, the call isn’t made via the other address. Thus it’s still unclear to me how to do this.

Hey @zkvonsnarkenstein.chain , first thing, are you using the last version of aeproject? Second I did this some time ago with the following logic.

before(async () => {
    client = await Universal({
        nodes: [{
            name: 'devnetNode',
            instance: await Node(config)
        }],
        accounts: [MemoryAccount({
            keypair: wallets[0]
        })],
        networkId: 'ae_devnet',
        compilerUrl: config.compilerUrl
    });
    nonClient = await Universal({
        nodes: [{
            name: 'devnetNode',
            instance: await Node(config)
        }],
        accounts: [MemoryAccount({
            keypair: wallets[1]
        })],
        networkId: 'ae_devnet',
        compilerUrl: config.compilerUrl
    });

and then for one client:

it(‘Login authorized user’, async () => {

    let user = await originsContract.methods.user_registration();
   
    assert.equal(user.result.returnType,'ok', 'user dont exist') 
});

and then for the other client:

it('Login unauthorized user', async () => {
    
    originsContract = await nonClient.getContractInstance(ORIGINS_CONTRACT, {contractAddress: originsContract.deployInfo.address});
   
   
    assert.isRejected(originsContract.methods.user_registration()) 
});

Let me know if that helps.

1 Like

the “Deployer” dependency is currently deprecated. please have a look at this guide:

install the latest aeproject version and initialize a new project. you can compare the generated files and dependencies there.

in the future it is planned to add the aeproject functionality to the CLI (which will probably renamed to aeternity-cli)

if everything goes fine we will also be able to introduce new features that will allow you to instantly mine blocks and other functions you’d want to see for smart contract development.

if you have specific requirements in what the tooling for smart contract development should support let me know!

2 Likes

I indeed was working with an old version. The reason for that was because I used npm install -g aeproject instead of npm i -g @aeternity/aeproject to install it.

It works, but installs an outdated version.

Tomorrow I will try the suggestions mentioned above, but the instructions look clear enough and what I see now matches what I get after installing the right version of aeproject.

2 Likes

so regarding that sending of different accounts (sorry I forgot to respond there)

=> you can initialize Universal with multiple different accounts (wallets[0], wallets[1], …)

for each specific transaction you perform you can specifiy an account via onAccount option that should be used for signing the transaction, see Transaction options - aeternity JavaScript SDK

you don’t need to initialize multiple Universal stamps to achieve that

1 Like