o1js
o1js copied to clipboard
Using `Struct` as state for a contract does not work properly inside `reducer-composite test`
Given the following example contract:
class Action extends Struct({
isIncrement: Bool,
data: Field,
}) {
static increment(count: number) {
return new this({
isIncrement: Bool(true),
data: Field(count),
});
}
static other(data: Field) {
return new this({
isIncrement: Bool(false),
data,
});
}
}
class CounterState extends Struct({
count: Field,
rollup: Field, // helper field to store the point in the action history that our on-chain state is at
}) {
static initial = new this({
count: Field(0),
rollup: Reducer.initialActionState,
});
}
class Counter extends SmartContract {
// the "reducer" field describes a type of action that we can dispatch, and reduce later
reducer = Reducer({ actionType: Action });
// on-chain version of our state. it will typically lag behind the
// version that's implicitly represented by the list of actions
@state(CounterState) state = State<CounterState>();
When we call contract.state.get().count
, we get incorrect values inside the reducer-composite test -- see this commit as an example here https://github.com/o1-labs/o1js/pull/1567/commits/442c3402594275d5709807fb8c5ed4fcbdc34158
since the reducer logic was completely rewritten since this, would be interesting to test it again and see if it works now 😅