flow-js-testing
flow-js-testing copied to clipboard
Logs cut leading zeroes of addresses
Problem
Logs cut leading zeroes of addresses.
(Related to https://github.com/onflow/flow-js-testing/issues/65#issuecomment-989876669).
Steps to Reproduce
flow.json:
{
"accounts": {
"emulator-account": {
"address": "f8d6e0586b0a20c7",
"key": "$PRIVATE_KEY"
}
},
"contracts": {},
"deployments": {},
"emulators": {
"default": {
"port": 3569,
"serviceAccount": "emulator-account"
}
},
"networks": {
"emulator": "127.0.0.1:3569",
"mainnet": "access.mainnet.nodes.onflow.org:9000",
"testnet": "access.devnet.nodes.onflow.org:9000"
}
}
Transaction (in cadence/transactions/log-signers.cdc):
transaction(message: String){
prepare(first: AuthAccount, second: AuthAccount){
log(message)
log(first.address)
log(second.address)
}
}
Test:
/**
* @jest-environment node
*/
import {
deployContractByName,
emulator,
executeScript,
getAccountAddress,
init,
sendTransaction,
} from 'flow-js-testing';
import path from 'path';
describe('flow sanity checks', () => {
beforeEach(async () => {
// eslint-disable-next-line unicorn/prefer-module
const basePath = path.resolve(__dirname, '../../cadence');
// You can specify different port to parallelize execution of describe blocks
const port = 8080;
await init(basePath, { port });
// Setting logging flag to true will pipe emulator output to console
const logging = false;
return emulator.start(port, logging);
});
afterEach(async () => {
// Stop emulator, so it could be restarted
return emulator.stop();
});
describe('log signers', () => {
it('given a transaction: logs out the signers', async () => {
const message = 'Hello from Emulator';
const Alice = await getAccountAddress('Alice');
const Bob = await getAccountAddress('Bob');
const signers = [Alice, Bob];
const consoleSpy = jest
.spyOn(console, 'log')
.mockImplementation(() => {});
emulator.setLogging(true);
await sendTransaction({
name: 'log-signers',
args: [message],
signers,
});
const transactionLogs = consoleSpy.mock.calls.toString();
consoleSpy.mockRestore();
const actual = [
transactionLogs.includes(message),
transactionLogs.includes(Alice),
transactionLogs.includes(Bob),
];
const expected = [true, true, true];
expect(actual).toEqual(expected);
});
});
});
This test fails and claims the second argument is false. The address of Alice is 0x01cf0e2f2f715450. But the output of console.log(transactionLogs) is:
LOG: time="2021-12-09T16:55:25+01:00" level=debug msg="🎁 GetLatestBlock called" blockHeight=3 blockID=ee98016d268630db54b814d18d0127edac8cc36f90d193c0c6f5fd4909bbd8b1
,LOG: time="2021-12-09T16:55:25+01:00" level=debug msg="👤 GetAccountAtLatestBlock called" address=f8d6e0586b0a20c7
,LOG: time="2021-12-09T16:55:26+01:00" level=debug msg="️✉️ Transaction submitted" txID=5a46897e60f13ee68e11ef754983fefe9ec7bc8a2ca6079f0665e404138735e9
,LOG: time="2021-12-09T16:55:26+01:00" level=info msg="⭐ Transaction executed" computationUsed=6 txID=5a46897e60f13ee68e11ef754983fefe9ec7bc8a2ca6079f0665e404138735e9
,LOG: time="2021-12-09T16:55:26+01:00" level=debug msg="\x1b[1;34mLOG\x1b[0m \x1b[2m[5a4689]\x1b[0m \"Hello from Emulator\""
time="2021-12-09T16:55:26+01:00" level=debug msg="\x1b[1;34mLOG\x1b[0m \x1b[2m[5a4689]\x1b[0m 0x1cf0e2f2f715450"
time="2021-12-09T16:55:26+01:00" level=debug msg="\x1b[1;34mLOG\x1b[0m \x1b[2m[5a4689]\x1b[0m 0x179b6b1cb6755e31"
time="2021-12-09T16:55:26+01:00" level=debug msg="📦 Block #4 committed" blockHeight=4 blockID=5fd780a98baad6d30f66cf75e76c3e1c9398097a9bb2e3f239f0cd7e166f6932
,LOG: time="2021-12-09T16:55:26+01:00" level=debug msg="📝 GetTransactionResult called" txID=5a46897e60f13ee68e11ef754983fefe9ec7bc8a2ca6079f0665e404138735e9
If you look closely, you'll see that it says 0x1cf0e2f2f715450, so its missing the zero after the x: 0x01cf0e2f2f715450.
Acceptance Criteria
Logging no longer cuts leading zeroes of addresses.
Context
A test that does assertions on logs inside of transactions.
@janhesters this is actually not framework, but rather Cadence itself :) You can read more about this "issue" here: https://github.com/onflow/cadence/issues/1131
And I absolutely love that log spy! ❤️ I can add this to return value of transaction and scripts, even though I would prefer it to be on emulator level 🤔
@MaxStalker If I understand the issue you linked correctly, this was fixed on November 4th?
So I was wondering, why is this still in the emulator? Am I misreading something?
@janhesters Oh... I thought that maybe CLI is still using old Cadence version, but it's on 0.20.1
@SupunS or @turbolent can you check why the issue still there?
I assume it is because even though this was fixed on master, the v0.20 branch was already forked from the master by then. So its not there in 0.20.*. But would be available from the next cadence release (next non-patch release).
Is this the expected behaviour? Or this is a bug? The Cadence version is v0.23.0.