anagrambuild / bonsol

solana + risc0
https://bonsol.sh
GNU Affero General Public License v3.0
60 stars 9 forks source link

bug: main build is failing with inconsistent error #63

Closed jac18281828 closed 1 month ago

jac18281828 commented 1 month ago

new program generated every time, but expect is constant. How does that work?

Seems like the build can still fail:

failures:

---- ingest::dragon::dragon_ingester_tests::v1_txns_pass stdout ----

error: expect test failed
   --> node/src/ingest/dragon.rs:269:13

You can update all `expect!` tests by running:

    env UPDATE_EXPECT=1 cargo test

To update a single test, place the cursor on `expect` token and use `run` feature of rust-analyzer.

Expect:
----
[
    BonsolInstruction {
        cpi: false,
        accounts: [
            1111111QLbz7JHiBTspS962RLKV8GndWFwiEaqKM,
        ],
        data: [
            0,
            0,
            0,
            0,
        ],
        last_known_block: 1,
    },
    BonsolInstruction {
        cpi: true,
        accounts: [
            1111111QLbz7JHiBTspS962RLKV8GndWFwiEaqKM,
        ],
        data: [
            0,
            0,
            0,
            0,
        ],
        last_known_block: 1,
    },
]
----

Actual:
----
[
    BonsolInstruction {
        cpi: false,
        accounts: [
            1111111ogCyDbaRMvkdsHB3qfdyFYaG1WtRUAfdh,
        ],
        data: [
            0,
            0,
            0,
            0,
        ],
        last_known_block: 1,
    },
    BonsolInstruction {
        cpi: true,
        accounts: [
            1111111ogCyDbaRMvkdsHB3qfdyFYaG1WtRUAfdh,
        ],
        data: [
            0,
            0,
            0,
            0,
        ],
        last_known_block: 1,
    },
]
----

Diff:
----
[
    BonsolInstruction {
        cpi: false,
        accounts: [
            1111111QLbz7JHiBTspS962RLKV8GndWFwiEaqKMogCyDbaRMvkdsHB3qfdyFYaG1WtRUAfdh,
        ],
        data: [
            0,
            0,
            0,
            0,
        ],
        last_known_block: 1,
    },
    BonsolInstruction {
        cpi: true,
        accounts: [
            1111111QLbz7JHiBTspS962RLKV8GndWFwiEaqKMogCyDbaRMvkdsHB3qfdyFYaG1WtRUAfdh,
        ],
        data: [
            0,
            0,
            0,
            0,
        ],
        last_known_block: 1,
    },
]
----
eureka-cpu commented 1 month ago

expect_test captures a snapshot of something, and checks against that snapshot for changes. This particular one is just supposed to check that the correct instructions are produced given some compiled and inner instructions to parse into bonsol instructions through a filter for some program key.

The error you are experiencing here is some non-determinism or impurity in producing account pubkey for those instructions. In a pure function, the same input will always produce the same output. The test here is the standard for ensuring that a parser is functionally correct and to prevent against regressions.

eureka-cpu commented 1 month ago

The problem was using Pubkey::new_unique(). We aren't testing anything that would need to generate unique keys here so setting it to a static key solves it.