Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rianhughes committed Aug 22, 2023
1 parent b385dd7 commit d3b2e7a
Showing 1 changed file with 35 additions and 22 deletions.
57 changes: 35 additions & 22 deletions rpc/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,27 @@ func TestClassAt(t *testing.T) {
for _, test := range testSet {
spy := NewSpy(testConfig.provider.c)
testConfig.provider.c = spy
class, err := testConfig.provider.ClassAt(context.Background(), WithBlockTag("latest"), test.ContractAddress)
resp, err := testConfig.provider.ClassAt(context.Background(), WithBlockTag("latest"), test.ContractAddress)
if err != nil {
t.Fatal(err)
}
diff, err := spy.Compare(class, false)
if err != nil {
t.Fatal("expecting to match", err)
}
if diff != "FullMatch" {
spy.Compare(class, true)
t.Fatal("structure expecting to be FullMatch, instead", diff)
}
if class == nil || class.Program == "" {
t.Fatal("code should exist")
switch class := resp.(type) {
case DepcreatedContractClass:
diff, err := spy.Compare(class, false)
if err != nil {
t.Fatal("expecting to match", err)
}
if diff != "FullMatch" {
spy.Compare(class, true)
t.Fatal("structure expecting to be FullMatch, instead", diff)
}
if class.Program == "" {
t.Fatal("code should exist")
}
case ContractClass:
panic("Not covered")
}

}
}

Expand Down Expand Up @@ -143,21 +149,28 @@ func TestClass(t *testing.T) {
for _, test := range testSet {
spy := NewSpy(testConfig.provider.c)
testConfig.provider.c = spy
class, err := testConfig.provider.Class(context.Background(), WithBlockTag("latest"), test.ClassHash)
resp, err := testConfig.provider.Class(context.Background(), WithBlockTag("latest"), test.ClassHash)
if err != nil {
t.Fatal(err)
}
diff, err := spy.Compare(class, false)
if err != nil {
t.Fatal("expecting to match", err)
}
if diff != "FullMatch" {
spy.Compare(class, true)
t.Fatal("structure expecting to be FullMatch, instead", diff)
}

if class == nil || !strings.HasPrefix(class.Program, test.ExpectedProgram) {
t.Fatal("code should exist")
switch class := resp.(type) {
case DepcreatedContractClass:

diff, err := spy.Compare(class, false)
if err != nil {
t.Fatal("expecting to match", err)
}
if diff != "FullMatch" {
spy.Compare(class, true)
t.Fatal("structure expecting to be FullMatch, instead", diff)
}

if !strings.HasPrefix(class.Program, test.ExpectedProgram) {
t.Fatal("code should exist")
}
case ContractClass:
panic("Not covered")
}
}
}
Expand Down

0 comments on commit d3b2e7a

Please sign in to comment.