Skip to content

Commit

Permalink
Adjust old target tests to use new diff
Browse files Browse the repository at this point in the history
  • Loading branch information
cristovaoth committed Feb 5, 2025
1 parent 3c2a8ca commit a8a44c3
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 28 deletions.
32 changes: 23 additions & 9 deletions packages/sdk/src/targets/applyTargets.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { expect, it, suite } from "vitest"
import { Operator, ParameterType, Target } from "zodiac-roles-deployments"
import { diffTargets } from "../diff"
import { ZeroHash } from "ethers"
import { normalizeCondition } from "../conditions"

import { replaceTargets } from "./applyTargets"
const roleKey = ZeroHash

suite("replaceTargets", () => {
it("should revoke function-scoped targets", () => {
Expand All @@ -25,13 +28,23 @@ suite("replaceTargets", () => {
]
const after: Target[] = []

expect(replaceTargets(before, after)).to.deep.equal([
const { minus, plus } = diffTargets({ roleKey, prev: before, next: after })

expect(minus).to.deep.equal([
{
call: "revokeTarget",
roleKey,
targetAddress: "0x9C58BAcC331c9aa871AFD802DB6379a98e80CEdb",
},
{
call: "revokeFunction",
roleKey,
targetAddress: "0x9C58BAcC331c9aa871AFD802DB6379a98e80CEdb",
selector: "0x095ea7b3",
},
])

expect(plus).to.deep.equal([])
})

it("should patch conditions", () => {
Expand Down Expand Up @@ -74,21 +87,22 @@ suite("replaceTargets", () => {
},
]

expect(replaceTargets(before, after)).to.deep.equal([
{
call: "scopeTarget",
targetAddress: "0x9C58BAcC331c9aa871AFD802DB6379a98e80CEdb",
},
const { minus, plus } = diffTargets({ roleKey, prev: before, next: after })

expect(minus).to.deep.equal([])

expect(plus).to.deep.equal([
{
call: "scopeFunction",
roleKey,
targetAddress: "0x9C58BAcC331c9aa871AFD802DB6379a98e80CEdb",
selector: "0x095ea7b3",
executionOptions: 0,
condition: {
condition: normalizeCondition({
paramType: ParameterType.None,
operator: Operator.Or,
children: [],
},
}),
},
])
})
Expand Down
69 changes: 50 additions & 19 deletions packages/sdk/src/targets/diffTargets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import {
ParameterType,
Target,
} from "zodiac-roles-deployments"
import { diffTargets } from "../diff"
import { ZeroHash } from "ethers"
import { normalizeCondition } from "../conditions"

import { diffTargets } from "./diffTargets"
const roleKey = ZeroHash

suite("diffTargets", () => {
it("should correctly diff target-cleared targets", () => {
Expand Down Expand Up @@ -41,22 +44,29 @@ suite("diffTargets", () => {
},
]

expect(diffTargets(a, b)).to.deep.equal([
{
address: "0x2",
clearance: Clearance.Target,
executionOptions: ExecutionOptions.None,
functions: [],
},
])
expect(diffTargets(b, a)).to.deep.equal([
{
address: "0x2",
clearance: Clearance.Target,
executionOptions: ExecutionOptions.Both,
functions: [],
},
])
expect(diffTargets({ roleKey, prev: a, next: b })).to.deep.equal({
minus: [],
plus: [
{
call: "allowTarget",
roleKey,
targetAddress: "0x2",
executionOptions: ExecutionOptions.Both,
},
],
})

expect(diffTargets({ roleKey, prev: b, next: a })).to.deep.equal({
minus: [
{
call: "allowTarget",
roleKey,
targetAddress: "0x2",
executionOptions: ExecutionOptions.None,
},
],
plus: [],
})
})

it("should diff functions based on all their properties including conditions", () => {
Expand Down Expand Up @@ -99,7 +109,28 @@ suite("diffTargets", () => {
},
]

expect(diffTargets(a, a)).to.deep.equal([])
expect(diffTargets(a, b)).to.deep.equal(a)
//expect(diffTargets(a, a)).to.deep.equal([])
expect(diffTargets({ roleKey, prev: a, next: a })).to.deep.equal({
minus: [],
plus: [],
})

//expect(diffTargets(a, b)).to.deep.equal(a)
expect(diffTargets({ roleKey, prev: b, next: a })).to.deep.equal({
minus: [],
plus: [
{
call: "scopeFunction",
roleKey,
targetAddress: "0x9C58BAcC331c9aa871AFD802DB6379a98e80CEdb",
selector: "0x095ea7b3",
executionOptions: 0,
condition: normalizeCondition({
paramType: ParameterType.None,
operator: Operator.Pass,
}),
},
],
})
})
})

0 comments on commit a8a44c3

Please sign in to comment.