Skip to content

Commit

Permalink
[DFI-850] dvm multi module compile (#224)
Browse files Browse the repository at this point in the history
* [DFI-850] prev version compatibility

* [DFI-850] added multiple compilation and tests

* [DFI-850] added metadata info

* [DFI-850] mapping proto fields

* [DFI-850] fixed dep

* [DFI-850] added mixed content compilation test

* [DFI-850] fixed compilationUnit name

* [DFI-850] fixed test

* [DFI-850] added multi publish

* [DFI-850] added multi publish v2

* [DFI-850] added test for cli/rest

* [DFI-850] added test for cli/rest

* [DFI-850] added integ test

* [DFI-850] fixes
  • Loading branch information
g3co authored Oct 22, 2020
1 parent 7fa4581 commit 18871c7
Show file tree
Hide file tree
Showing 28 changed files with 990 additions and 348 deletions.
16 changes: 10 additions & 6 deletions app/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"github.com/cosmos/cosmos-sdk/x/mint"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/cosmos/cosmos-sdk/x/supply"
"github.com/dfinance/dvm-proto/go/compiler_grpc"
"github.com/dfinance/dvm-proto/go/metadata_grpc"
"github.com/dfinance/dvm-proto/go/vm_grpc"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
Expand Down Expand Up @@ -183,9 +185,10 @@ func MockVMConfig() *vmConfig.VMConfig {

// VMServer aggregates gRPC VM services.
type VMServer struct {
vm_grpc.UnimplementedVMCompilerServer
vm_grpc.UnimplementedVMModulePublisherServer
vm_grpc.UnimplementedVMScriptExecutorServer
VMCompilerServer compiler_grpc.UnimplementedDvmCompilerServer
VMMetaDataServer metadata_grpc.UnimplementedDVMBytecodeMetadataServer
VMModulePublisherServer vm_grpc.UnimplementedVMModulePublisherServer
VMScriptExecutorServer vm_grpc.UnimplementedVMScriptExecutorServer
}

// NewTestDnAppMockVM creates dnode app and mock VM server.
Expand All @@ -197,9 +200,10 @@ func NewTestDnAppMockVM(logOpts ...log.Option) (*DnServiceApp, func()) {
vmServer := VMServer{}
server := grpc.NewServer()

vm_grpc.RegisterVMCompilerServer(server, &vmServer.UnimplementedVMCompilerServer)
vm_grpc.RegisterVMModulePublisherServer(server, &vmServer.UnimplementedVMModulePublisherServer)
vm_grpc.RegisterVMScriptExecutorServer(server, &vmServer.UnimplementedVMScriptExecutorServer)
compiler_grpc.RegisterDvmCompilerServer(server, &vmServer.VMCompilerServer)
metadata_grpc.RegisterDVMBytecodeMetadataServer(server, &vmServer.VMMetaDataServer)
vm_grpc.RegisterVMModulePublisherServer(server, &vmServer.VMModulePublisherServer)
vm_grpc.RegisterVMScriptExecutorServer(server, &vmServer.VMScriptExecutorServer)

go func() {
if err := server.Serve(vmListener); err != nil {
Expand Down
39 changes: 29 additions & 10 deletions app/integ_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dfinance/dvm-proto/go/vm_grpc"
"github.com/dfinance/dvm-proto/go/compiler_grpc"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
Expand Down Expand Up @@ -155,17 +155,24 @@ func TestIntegApp_Crisis(t *testing.T) {
// compile and deploy module
{
// compile
byteCode, compileErr := vm_client.Compile(dvmAddr, &vm_grpc.SourceFile{
Text: swapModuleSrc,
byteCode, compileErr := vm_client.Compile(dvmAddr, &compiler_grpc.SourceFiles{
Units: []*compiler_grpc.CompilationUnit{
{
Text: swapModuleSrc,
Name: "swapModuleSrc",
},
},
Address: client1LibraAddr,
})

require.NoError(t, compileErr)
require.Len(t, byteCode, 1)

// deploy using helper func
senderAcc, senderPrivKey := GetAccountCheckTx(app, client1Addr), client1PrivKey
deployMsg := vm.MsgDeployModule{
Signer: client1Addr,
Module: byteCode,
Module: []vm.Contract{byteCode[0].ByteCode},
}
tx := GenTx([]sdk.Msg{deployMsg}, []uint64{senderAcc.GetAccountNumber()}, []uint64{senderAcc.GetSequence()}, senderPrivKey)
CheckDeliverTx(t, app, tx)
Expand Down Expand Up @@ -199,11 +206,17 @@ func TestIntegApp_Crisis(t *testing.T) {

// compile
createSwapScriptSrc := strings.ReplaceAll(createSwapScriptSrcFmt, "{{sender}}", client1Addr.String())
byteCode, compileErr := vm_client.Compile(dvmAddr, &vm_grpc.SourceFile{
Text: createSwapScriptSrc,
byteCode, compileErr := vm_client.Compile(dvmAddr, &compiler_grpc.SourceFiles{
Units: []*compiler_grpc.CompilationUnit{
{
Text: createSwapScriptSrc,
Name: "createSwapScriptSrc",
},
},
Address: client1LibraAddr,
})
require.NoError(t, compileErr)
require.Len(t, byteCode, 1)

// prepare execute Tx
swapAmountArg, amountArgErr := vm_client.NewU128ScriptArg(offerAmount.String())
Expand All @@ -214,7 +227,7 @@ func TestIntegApp_Crisis(t *testing.T) {
senderAcc, senderPrivKey := GetAccountCheckTx(app, client1Addr), client1PrivKey
executeMsg := vm.MsgExecuteScript{
Signer: client1Addr,
Script: byteCode,
Script: byteCode[0].ByteCode,
Args: []vm.ScriptArg{swapAmountArg, swapPriceArg},
}
tx := GenTx([]sdk.Msg{executeMsg}, []uint64{senderAcc.GetAccountNumber()}, []uint64{senderAcc.GetSequence()}, senderPrivKey)
Expand Down Expand Up @@ -258,11 +271,17 @@ func TestIntegApp_Crisis(t *testing.T) {
suppliesBefore := GetAllSupplies(t, app, GetContext(app, true))

createSwapScriptSrc := strings.ReplaceAll(swapSwapScriptSrcFmt, "{{sender}}", client1Addr.String())
byteCode, compileErr := vm_client.Compile(dvmAddr, &vm_grpc.SourceFile{
Text: createSwapScriptSrc,
byteCode, compileErr := vm_client.Compile(dvmAddr, &compiler_grpc.SourceFiles{
Units: []*compiler_grpc.CompilationUnit{
{
Text: createSwapScriptSrc,
Name: "createSwapScriptSrc",
},
},
Address: client1LibraAddr,
})
require.NoError(t, compileErr)
require.Len(t, byteCode, 1)

sellerAddrArg, sellerArgErr := vm_client.NewAddressScriptArg(client1Addr.String())
require.NoError(t, sellerArgErr)
Expand All @@ -272,7 +291,7 @@ func TestIntegApp_Crisis(t *testing.T) {
senderAcc, senderPrivKey := GetAccountCheckTx(app, client2Addr), client2PrivKey
executeMsg := vm.MsgExecuteScript{
Signer: client2Addr,
Script: byteCode,
Script: byteCode[0].ByteCode,
Args: []vm.ScriptArg{sellerAddrArg, swapPriceArg},
}
tx := GenTx([]sdk.Msg{executeMsg}, []uint64{senderAcc.GetAccountNumber()}, []uint64{senderAcc.GetSequence()}, senderPrivKey)
Expand Down
Loading

0 comments on commit 18871c7

Please sign in to comment.