Skip to content

Commit

Permalink
update chain writer to emit events for interface tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EasterTheBunny committed Feb 19, 2025
1 parent 0661f05 commit 1e833fb
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 18 deletions.
10 changes: 8 additions & 2 deletions contracts/programs/contract-reader-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,21 @@ pub mod contract_reader_interface {
Ok(())
}

pub fn create_event(_ctx: Context<Initialize>, str_data: TestStructData) -> Result<()> {
pub fn createevent(_ctx: Context<Events>, data: TestStructData) -> Result<()> {
emit!(TestEvent {
data: str_data,
data: data,
});

Ok(())
}
}

#[derive(Accounts)]
pub struct Events<'info> {
pub signer: Signer<'info>,
pub system_program: Program<'info, System>,
}

#[derive(Accounts)]
#[instruction(test_idx: u64)]
pub struct Initialize<'info> {
Expand Down
59 changes: 43 additions & 16 deletions integration-tests/relayinterface/chain_components_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func DisableTests(it *SolanaChainComponentsInterfaceTester[*testing.T]) {
ContractReaderGetLatestValueWithFilteringForEvent,
// query key not implemented yet
// ContractReaderQueryKeyNotFound,
ContractReaderQueryKeyReturnsData,
// ContractReaderQueryKeyReturnsData,
ContractReaderQueryKeyReturnsDataAsValuesDotValue,
ContractReaderQueryKeyCanFilterWithValueComparator,
ContractReaderQueryKeyCanLimitResultsWithCursor,
Expand Down Expand Up @@ -797,7 +797,6 @@ func (it *SolanaChainComponentsInterfaceTester[T]) buildContractReaderConfig(t T
pdaStructDataPrefix := []byte("struct_data")
pdaStructDataPrefix = binary.LittleEndian.AppendUint64(pdaStructDataPrefix, idx)
testStruct := CreateTestStruct(0, it)
locator := commoncodec.ElementExtractorLocationFirst
uint64ReadDef := config.ReadDefinition{
ChainSpecificName: "DataAccount",
ReadType: config.Account,
Expand Down Expand Up @@ -983,20 +982,7 @@ func (it *SolanaChainComponentsInterfaceTester[T]) buildContractReaderConfig(t T
ChainSpecificName: "TestEvent",
ReadType: config.Event,
OutputModifications: commoncodec.ModifiersConfig{
&commoncodec.ElementExtractorModifierConfig{
Extractions: map[string]*commoncodec.ElementExtractorLocation{"Data": &locator},
},
&commoncodec.HardCodeModifierConfig{
OnChainValues: map[string]any{
"DifferentField": copy(make([]byte, 32), []byte(testStruct.DifferentField)),
"NestedDynamicStruct.Inner.S": copy(make([]byte, 32), []byte(testStruct.NestedDynamicStruct.Inner.S)),
},
OffChainValues: map[string]any{
"ExtraField": AnyExtraValue,
"DifferentField": testStruct.DifferentField,
"NestedDynamicStruct.Inner.S": testStruct.NestedDynamicStruct.Inner.S,
},
},
&commoncodec.PropertyExtractorConfig{FieldName: "Data"},
&commoncodec.AddressBytesToStringModifierConfig{
Fields: []string{"AccountStruct.AccountStr"},
},
Expand Down Expand Up @@ -1362,6 +1348,47 @@ func (it *SolanaChainComponentsInterfaceTester[T]) buildContractWriterConfig(t T
},
DebugIDLocation: "",
},
MethodTriggeringEvent: {
FromAddress: fromAddress,
InputModifications: []commoncodec.ModifierConfig{
&commoncodec.PropertyExtractorConfig{FieldName: "Data"},
&commoncodec.AddressBytesToStringModifierConfig{
Fields: []string{"AccountStruct.AccountStr"},
},
&commoncodec.HardCodeModifierConfig{
OnChainValues: map[string]any{
"Padding0": []byte{},
"Padding1": []byte{},
"Padding2": []byte{},
"NestedDynamicStruct.Padding": []byte{},
"NestedStaticStruct.Padding": []byte{},
"DifferentField": copy(make([]byte, 32), []byte(testStruct.DifferentField)),
"NestedDynamicStruct.Inner.S": copy(make([]byte, 32), []byte(testStruct.NestedDynamicStruct.Inner.S)),
},
OffChainValues: map[string]any{
"DifferentField": testStruct.DifferentField,
"NestedDynamicStruct.Inner.S": testStruct.NestedDynamicStruct.Inner.S,
},
},
},
ChainSpecificName: "createevent",
LookupTables: chainwriter.LookupTables{},
Accounts: []chainwriter.Lookup{
{AccountConstant: &chainwriter.AccountConstant{
Name: "Signer",
Address: fromAddress,
IsSigner: true,
IsWritable: true,
}},
{AccountConstant: &chainwriter.AccountConstant{
Name: "SystemProgram",
Address: solana.SystemProgramID.String(),
IsWritable: false,
IsSigner: false,
}},
},
DebugIDLocation: "",
},
},
},
AnySecondContractName: {
Expand Down

0 comments on commit 1e833fb

Please sign in to comment.