-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(axelar-std): add derive macro unit tests (#170)
- Loading branch information
1 parent
b672e2f
commit f52dded
Showing
17 changed files
with
224 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
use soroban_sdk::testutils::Address as _; | ||
use soroban_sdk::{contract, contractimpl, Address, Env, String}; | ||
use stellar_axelar_std::events::{fmt_last_emitted_event, Event}; | ||
use stellar_axelar_std::IntoEvent; | ||
|
||
#[contract] | ||
pub struct Contract; | ||
|
||
#[derive(Debug, PartialEq, Eq, IntoEvent)] | ||
struct EmptyEvent; | ||
|
||
#[derive(Debug, PartialEq, Eq, IntoEvent)] | ||
struct SingleDataEvent { | ||
topic1: Address, | ||
topic2: Address, | ||
#[data] | ||
data: String, | ||
} | ||
|
||
#[derive(Debug, PartialEq, Eq, IntoEvent)] | ||
#[event_name("custom_name")] | ||
struct NamedEvent { | ||
topic: Address, | ||
#[data] | ||
data: String, | ||
} | ||
|
||
#[derive(Debug, PartialEq, Eq, IntoEvent)] | ||
struct MultiDataEvent { | ||
topic1: String, | ||
topic2: Address, | ||
#[data] | ||
data1: String, | ||
#[data] | ||
data2: String, | ||
} | ||
|
||
#[derive(Debug, PartialEq, Eq, IntoEvent)] | ||
struct NoDataEvent { | ||
topic1: String, | ||
topic2: Address, | ||
} | ||
|
||
#[derive(Debug, PartialEq, Eq, IntoEvent)] | ||
struct NoTopicEvent { | ||
#[data] | ||
data1: String, | ||
#[data] | ||
data2: Address, | ||
#[data] | ||
data3: String, | ||
} | ||
|
||
#[contractimpl] | ||
impl Contract { | ||
pub const fn __constructor() {} | ||
|
||
pub fn empty(env: &Env) { | ||
EmptyEvent.emit(env); | ||
} | ||
|
||
pub fn single_data(env: &Env, topic1: Address, topic2: Address, data: String) { | ||
SingleDataEvent { | ||
topic1, | ||
topic2, | ||
data, | ||
} | ||
.emit(env); | ||
} | ||
|
||
pub fn named(env: &Env, topic: Address, data: String) { | ||
NamedEvent { topic, data }.emit(env); | ||
} | ||
|
||
pub fn multi_data(env: &Env, topic1: String, topic2: Address, data1: String, data2: String) { | ||
MultiDataEvent { | ||
topic1, | ||
topic2, | ||
data1, | ||
data2, | ||
} | ||
.emit(env); | ||
} | ||
|
||
pub fn no_data(env: &Env, topic1: String, topic2: Address) { | ||
NoDataEvent { topic1, topic2 }.emit(env); | ||
} | ||
|
||
pub fn no_topic(env: &Env, data1: String, data2: Address, data3: String) { | ||
NoTopicEvent { | ||
data1, | ||
data2, | ||
data3, | ||
} | ||
.emit(env); | ||
} | ||
} | ||
|
||
#[test] | ||
fn event_empty_succeeds() { | ||
let env = &Env::default(); | ||
|
||
let contract_id = env.register(Contract, ()); | ||
let client = ContractClient::new(env, &contract_id); | ||
|
||
client.empty(); | ||
goldie::assert!(fmt_last_emitted_event::<EmptyEvent>(env)); | ||
} | ||
|
||
#[test] | ||
fn single_data_event_emitted() { | ||
let env = &Env::default(); | ||
|
||
let contract_id = env.register(Contract, ()); | ||
let client = ContractClient::new(env, &contract_id); | ||
|
||
let topic1 = Address::generate(env); | ||
let topic2 = Address::generate(env); | ||
let data = String::from_str(env, "100"); | ||
|
||
client.single_data(&topic1, &topic2, &data); | ||
goldie::assert!(fmt_last_emitted_event::<SingleDataEvent>(env)); | ||
} | ||
|
||
#[test] | ||
fn named_event_emitted() { | ||
let env = &Env::default(); | ||
|
||
let contract_id = env.register(Contract, ()); | ||
let client = ContractClient::new(env, &contract_id); | ||
|
||
let topic = Address::generate(env); | ||
let data = String::from_str(env, "100"); | ||
|
||
client.named(&topic, &data); | ||
goldie::assert!(fmt_last_emitted_event::<NamedEvent>(env)); | ||
} | ||
|
||
#[test] | ||
fn multi_data_event_emitted() { | ||
let env = &Env::default(); | ||
|
||
let contract_id = env.register(Contract, ()); | ||
let client = ContractClient::new(env, &contract_id); | ||
|
||
let topic1 = String::from_str(env, "topic-1"); | ||
let topic2 = Address::generate(env); | ||
let data1 = String::from_str(env, "data-1"); | ||
let data2 = String::from_str(env, "data-2"); | ||
|
||
client.multi_data(&topic1, &topic2, &data1, &data2); | ||
goldie::assert!(fmt_last_emitted_event::<MultiDataEvent>(env)); | ||
} | ||
|
||
#[test] | ||
fn no_data_event_emitted() { | ||
let env = &Env::default(); | ||
|
||
let contract_id = env.register(Contract, ()); | ||
let client = ContractClient::new(env, &contract_id); | ||
|
||
let topic1 = String::from_str(env, "topic-1"); | ||
let topic2 = Address::generate(env); | ||
|
||
client.no_data(&topic1, &topic2); | ||
goldie::assert!(fmt_last_emitted_event::<NoDataEvent>(env)); | ||
} | ||
|
||
#[test] | ||
fn no_topic_event_emitted() { | ||
let env = &Env::default(); | ||
|
||
let contract_id = env.register(Contract, ()); | ||
let client = ContractClient::new(env, &contract_id); | ||
|
||
let data1 = String::from_str(env, "data-1"); | ||
let data2 = Address::generate(env); | ||
let data3 = String::from_str(env, "data-3"); | ||
|
||
client.no_topic(&data1, &data2, &data3); | ||
goldie::assert!(fmt_last_emitted_event::<NoTopicEvent>(env)); | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/axelar-std/tests/testdata/event_custom_multiple_topics_and_data_succeeds.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
contract: Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4) | ||
topics: (Symbol(emitted_data), String(topic-1), Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M)) | ||
data: (String(data-1), String(data-2)) |
3 changes: 3 additions & 0 deletions
3
packages/axelar-std/tests/testdata/event_empty_succeeds.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
contract: Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM) | ||
topics: (Symbol(empty)) | ||
data: () |
3 changes: 3 additions & 0 deletions
3
packages/axelar-std/tests/testdata/event_multi_data_succeeds.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
contract: Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM) | ||
topics: (Symbol(multi_data), String(topic-1), Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4)) | ||
data: (String(data-1), String(data-2)) |
3 changes: 3 additions & 0 deletions
3
packages/axelar-std/tests/testdata/event_named_succeeds.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
contract: Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM) | ||
topics: (Symbol(custom_name), Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4)) | ||
data: (String(100)) |
3 changes: 3 additions & 0 deletions
3
packages/axelar-std/tests/testdata/event_no_data_succeeds.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
contract: Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM) | ||
topics: (Symbol(no_data), String(topic-1), Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4)) | ||
data: () |
3 changes: 3 additions & 0 deletions
3
packages/axelar-std/tests/testdata/event_no_topic_succeeds.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
contract: Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM) | ||
topics: (Symbol(no_topic)) | ||
data: (String(data-1), Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4), String(data-3)) |
3 changes: 3 additions & 0 deletions
3
packages/axelar-std/tests/testdata/event_single_data_succeeds.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
contract: Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM) | ||
topics: (Symbol(single_data), Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4), Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M)) | ||
data: (String(100)) |
3 changes: 3 additions & 0 deletions
3
packages/axelar-std/tests/testdata/event_transfer_emission_succeeds.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
contract: Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4) | ||
topics: (Symbol(transferred), Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M), Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAITA4)) | ||
data: (String(100)) |
3 changes: 3 additions & 0 deletions
3
packages/axelar-std/tests/testdata/multi_data_event_emitted.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
contract: Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM) | ||
topics: (Symbol(multi_data), String(topic-1), Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4)) | ||
data: (String(data-1), String(data-2)) |
3 changes: 3 additions & 0 deletions
3
packages/axelar-std/tests/testdata/named_event_emitted.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
contract: Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM) | ||
topics: (Symbol(custom_name), Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4)) | ||
data: (String(100)) |
3 changes: 3 additions & 0 deletions
3
packages/axelar-std/tests/testdata/no_data_event_emitted.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
contract: Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM) | ||
topics: (Symbol(no_data), String(topic-1), Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4)) | ||
data: () |
3 changes: 3 additions & 0 deletions
3
packages/axelar-std/tests/testdata/no_topic_event_emitted.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
contract: Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM) | ||
topics: (Symbol(no_topic)) | ||
data: (String(data-1), Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4), String(data-3)) |
3 changes: 3 additions & 0 deletions
3
packages/axelar-std/tests/testdata/single_data_event_emitted.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
contract: Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM) | ||
topics: (Symbol(single_data), Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4), Contract(CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M)) | ||
data: (String(100)) |