Skip to content

Commit

Permalink
fixing ethereum event filter validation by filtering out "this" (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
adridadou authored Aug 26, 2020
1 parent 250d425 commit b575f8f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,27 @@ final case class VariableName(name: String) extends Expression {
executionResult: TemplateExecutionResult
): Result[List[VariableName]] =
executionResult.getExpression(this) match {
case Some(
VariableDefinition(
_,
Some(
VariableTypeDefinition(
EthereumEventFilterType.name,
typeParameter
)
),
_,
_,
_,
defaultValue
)
) =>
defaultValue
.map(_.variables(executionResult))
.sequence
.map(_.getOrElse(Nil))
.map(List(this) ++ _)
.map(_.filter(_.name =!= "this"))
case Some(variable: VariableDefinition) =>
variable.defaultValue
.map(_.variables(executionResult))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2353,6 +2353,7 @@ class OpenlawExecutionEngineSpec extends FlatSpec with Matchers {

val Success(newCollection) =
result.evaluate[CollectionValue]("new collection")

newCollection.values shouldBe Map(
0 -> "one world",
1 -> "two world",
Expand Down Expand Up @@ -2944,6 +2945,34 @@ class OpenlawExecutionEngineSpec extends FlatSpec with Matchers {
println(s"render time: ${renderTime - executionTime}ms")
}

it should "work fine with event filters" in {
val template = compile(
"""<%
|[[info: OLInfo]]
|%>
|__*[[Signer Email: Identity | Signature]]*__
|0x[[Signer EthAddress: EthAddress]]
|\right *[[info.id]]*
|[[Post:EthereumCall(
|contract:"0xE735B7Ca5F4865A688Df3d3a49A462066f24ff2A";
|interface:[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"string","name":"ID","type":"string"}],"name":"Post","type":"event"},{"constant":true,"inputs":[],"name":"ID","outputs":[{"internalType":"string","name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"string","name":"_ID","type":"string"}],"name":"post","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}];
|network:"Rinkeby";
|from:Signer EthAddress;
|function:"post";
|arguments:info.id)]]
|[[Post Data]]
|[[Post Event: EthereumEventFilter(
| contract address:"0xE735B7Ca5F4865A688Df3d3a49A462066f24ff2A";
| interface:[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"string","name":"ID","type":"string"}],"name":"Post","type":"event"}];
| event type name: "Post";
| conditional filter: this.ID = Post Data)]]
|This event value is: [[Post Event.event.ID]]""".stripMargin
)
val Success(result) = engine.execute(template)
val Success(validationResult) = result.validateExecution
validationResult.validationExpressionErrors shouldBe Nil
}

it should "be possible to re-define a formatter" in {
val template =
compile("""[[some value:Identity | signature]]""".stripMargin)
Expand Down

0 comments on commit b575f8f

Please sign in to comment.